Skip to content

Conversation

@mrafnadeem-apimatic
Copy link
Contributor

Why

In order to be able to relax enum validation during deserialization, we had two options:

  1. We can make the enum property nullable in the SDK so that when we deserialize the response and it doesn't match any existing enum value, it assigns null.
  2. We can add a new special enum value (like _Unknown) in the SDK so that when we deserialize the response and it doesn't match any existing enum value, it assigns that special enum value.

Since nullable properties already have a set meaning, it wouldn't make sense to cause confusion by giving null yet another purpose. The second option allows us to be more explicit about what we mean when we allow any unknown values during deserialization.

Therefore, the second option has been implemented.

What

  • Added new type of JsonConverter to gracefully handle cases where we get unexpected enum values in the response
  • Added tests for the new JsonConverter

Closes #65

Type of change

Select multiple if applicable.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause a breaking change)
  • Tests (adds or updates tests)
  • Documentation (adds or updates documentation)
  • Refactor (style improvements, performance improvements, code refactoring)
  • Revert (reverts a commit)
  • CI/Build (adds or updates a script, change in external dependencies)

Dependency Change

N/A

Breaking change

N/A

Testing

List the steps that were taken to test the changes

Checklist

  • My code follows the coding conventions
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added new unit tests

@mrafnadeem-apimatic mrafnadeem-apimatic added the enhancement New feature or request label Apr 1, 2024
@mrafnadeem-apimatic mrafnadeem-apimatic self-assigned this Apr 1, 2024
@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 2, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@mrafnadeem-apimatic mrafnadeem-apimatic merged commit 20bd007 into main Apr 2, 2024
@mrafnadeem-apimatic mrafnadeem-apimatic deleted the 65-relaxing-enum-validation-at-deserialization branch April 2, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Handling for Relaxing Enum Validation at Deserialization Time

3 participants