Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Product.type to Support Both String and Enum Values with Enhanced Deserialization #463

Conversation

armando-rodriguez-cko
Copy link
Contributor

@armando-rodriguez-cko armando-rodriguez-cko commented Jan 16, 2025

Update Product.type to Support Both String and Enum Values with Enhanced Deserialization

Description:

This PR extends the previous implementation of Product.type by refining the deserialization logic to dynamically map JSON keys to object fields while supporting both ProductType enum and custom string values for type. Additional validation, error handling, and test cases are added to ensure robustness.


Key Changes:

Code Enhancements:

  1. Product Class:

    • Refactored type property to retain flexibility for both ProductType enum and custom string values.
    • Updated getter methods:
      • getTypeAsEnum(): Returns the type as ProductType if applicable.
      • getTypeAsString(): Returns the type as a string if applicable.
  2. GsonSerializer:

    • Improved deserialization with the following updates:
      • JSON keys are now dynamically mapped to Product fields using reflection.
      • Robust error handling for invalid or unexpected JSON fields.
      • Automatic handling of nested fields and date formats.
    • Added support for multiple date formats during deserialization, including:
      • yyyy-MM-dd
      • ISO-8601
      • Numeric formats like yyyyMMdd.
  3. Unit Tests:

    • Expanded test coverage to include:
      • Validation of dynamic mapping of JSON keys to Product fields.
      • Handling of invalid or missing type values.
      • Support for multiple date formats during deserialization.
      • Mixed Product types (ProductType enum and custom string) within payment items.

New Test Cases:

  • GsonSerializerTest:

    • Verifies deserialization of Product with:
      • Valid enum (ProductType) values.
      • Unknown or custom string type values.
      • Null or missing type.
      • Mixed date formats in JSON.
  • GetPaymentsTestIT:

    • Validates:
      • Payments with Product items using both enum and string type.
      • Mixed scenarios with multiple items in a single payment.
      • JSON key mapping for additional Product fields.

Impact:

  • Enhanced Deserialization:
    • Dynamic mapping ensures compatibility with various JSON structures.
  • Flexibility:
    • Supports future extensions without requiring updates to the ProductType enum.
  • Error Handling:
    • Comprehensive validation ensures graceful handling of malformed JSON.
  • Backward Compatibility:
    • Existing consumers relying on ProductType remain unaffected.

Additional Notes:

  • The new deserialization logic introduces minimal overhead while significantly improving flexibility and reliability.
  • Downstream consumers should ensure compatibility with the enhanced Product.type handling.
  • The GsonSerializer improvements align with best practices for extensible and maintainable SDK development.

@armando-rodriguez-cko armando-rodriguez-cko requested a review from a team January 16, 2025 12:53
@armando-rodriguez-cko armando-rodriguez-cko force-pushed the feature/INT-1542-add-new-enum-values-to-product-type-or-update-product-type-to-be-a-string-value-java-skd branch from 56238b2 to 6f5f858 Compare January 17, 2025 11:25
@armando-rodriguez-cko armando-rodriguez-cko force-pushed the feature/INT-1542-add-new-enum-values-to-product-type-or-update-product-type-to-be-a-string-value-java-skd branch from 6f5f858 to e8d5ee6 Compare January 17, 2025 11:34
@armando-rodriguez-cko armando-rodriguez-cko changed the title Update Product.type to Support Both String and Enum Values Update Product.type to Support Both String and Enum Values with Enhanced Deserialization Jan 17, 2025
@armando-rodriguez-cko armando-rodriguez-cko merged commit 0fed925 into master Jan 17, 2025
4 checks passed
@armando-rodriguez-cko armando-rodriguez-cko deleted the feature/INT-1542-add-new-enum-values-to-product-type-or-update-product-type-to-be-a-string-value-java-skd branch January 17, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants