Skip to content

feat: ProviderEvaluation json de/serialization support #487

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

Conversation

Kavindu-Dodan
Copy link
Contributor

@Kavindu-Dodan Kavindu-Dodan commented Jun 22, 2023

This PR

Fixes #483 by adding annotations and accessors to required classes.

Testing

Unit tests were added to validate each class's compliance on json de/serialization support

@Kavindu-Dodan Kavindu-Dodan requested a review from a team as a code owner June 22, 2023 20:26
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Jun 22, 2023

Codecov Report

Merging #487 (07d01c4) into main (6cd588b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##               main     #487   +/-   ##
=========================================
  Coverage     94.44%   94.45%           
- Complexity      268      269    +1     
=========================================
  Files            25       25           
  Lines           612      613    +1     
  Branches         36       36           
=========================================
+ Hits            578      579    +1     
  Misses           17       17           
  Partials         17       17           
Flag Coverage Δ
unittests 94.45% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...in/java/dev/openfeature/sdk/ImmutableMetadata.java 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines +66 to +77
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.15.2</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>

Copy link
Member

@toddbaert toddbaert Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about adding these jackson dependencies.

I believe jackson can use javax.xml annotations. I think we should use those instead since they are standard.

Copy link
Contributor Author

@Kavindu-Dodan Kavindu-Dodan Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't personally used jaxb for json de/serialization. Besides, built-in support for Java SE for jaxb is removed from Java 9+ [1]

If we need to support de/serialization, I believe we will have some sort of dependency to a library. Here, my observation was thatcom.fasterxml.jackson.core: jackson-databind is anyway needed for @Jacksonized annotation.

[1] - https://openjdk.org/jeps/320

Copy link
Member

@toddbaert toddbaert Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, built-in support for Java SE for jaxb is removed from Java 9+

That's a bummer.

I have to think about this a bit more. As I mentioned in the original issue, my enthusiasm for supporting this was predicated on it not adding more dependencies. Right now we have only slf4j as an actual dependency. This adds significantly more.

Here, my observation was thatcom.fasterxml.jackson.core: jackson-databind is anyway needed for @Jacksonized annotation.

Oh - I didn't read enough into the lombok annotation. I just though it added POJO methods that jackson used via reflection or something. You're right that it seems to be adding jackson annotations though.

I don't think this is a great idea at this point. I feel like adding a json parsing related dep is too far. I wonder what @lopitz and @justinabrahms think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toddbaert , @Kavindu-Dodan

Jackson is just on json serializer/deserializer. There's also JSON and JAXB implementations and I guess a gazillion others. imho, we should not rely on jackson, just because a single user complains about it being hard to use. seems like the real issue is the missing default constructor in the dto. hence, i'd simply add a @NoArgsConstructor annotation and leave it with that. Looking at this class tells me also, that it is fine, as it is a @Data annotated class and not a @Value annotated one. I guess, we should have a default constructor for all data classes to stay consistent and allow for things like object creation via reflection...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toddbaert , @Kavindu-Dodan

Jackson is just on json serializer/deserializer. There's also JSON and JAXB implementations and I guess a gazillion others. imho, we should not rely on jackson, just because a single user complains about it being hard to use. seems like the real issue is the missing default constructor in the dto. hence, i'd simply add a @NoArgsConstructor annotation and leave it with that. Looking at this class tells me also, that it is fine, as it is a @Data annotated class and not a @Value annotated one.

I agree. I was hopeful that JAXB bindings would solve this issue for us, but I found out in this thread they're non-standard after Java9.

I guess, we should have a default constructor for all data classes to stay consistent and allow for things like object creation via reflection...

Ya, like I said in the associated issue, I think supporting an empty constructor is a good idea, and we should probably do so for all such "DTO" classes.

Copy link
Contributor Author

@Kavindu-Dodan Kavindu-Dodan Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @lopitz & @toddbaert for your suggestions.

I checked your proposals but still, there's a blocker to proceed here. The de/serialization error is there because of the ImmutableMetadata class [1]. This class was made immutable as this is a recommendation from the spec [2]. Given that ImmutableMetadata is a special class, I do not see a workaround to this.

I also think adding 3rd party libraries to support such a use case is NOT justifiable as this goes away from being simple. And the best recommendation would be to propose custom wrappers for de/serialization purposes.

[1] - https://github.com/open-feature/java-sdk/blob/main/src/main/java/dev/openfeature/sdk/ProviderEvaluation.java#L17
[2] - https://github.com/open-feature/spec/blob/main/specification/sections/01-flag-evaluation.md#conditional-requirement-14141

Copy link
Member

@toddbaert toddbaert Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can still add the empty constructor. I t might make things easier, though it doesn't solve the entire problem.

I'll open a PR for that if there's no objections.

UPDATE: opened #491

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toddbaert Thank you for the #491

With this conclusion, I will close this PR as we agree on not exposing any specific annotation support

@toddbaert toddbaert self-requested a review June 23, 2023 20:12
Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here.

@Kavindu-Dodan
Copy link
Contributor Author

we will not support a specific JSON de/serialization framework, however #491 will help with empty constructor support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ProviderEvaluation is hard to serialize / deserialize
3 participants