Skip to content

Conversation

@Danny02
Copy link
Contributor

@Danny02 Danny02 commented Oct 19, 2022

Why:
We want to use @AvroDefault with @nullable.

How does it help with resolving the issue:
The schema generation automaticly picks the right order of the union type.

Side effects:
This change has no side effects, because:

  • The order of union types is irrelevant for schema compability.
  • This change enables definitions wich has been invalid.

What is the purpose of the change

Implementing AVRO-3649.

Verifying this change

  • Added test that validates that a correct schema is generated

Documentation

  • This is my big question. Is the reflection serialization documented anywhere?

Why:
We want to use @AvroDefault with @nullable.

How does it help with resolving the issue:
The schema generation automaticly picks the right order of the union
type.

Side effects:
This change has no side effects, because:
- The order of union types is irrelevant for schema compability.
- This change enables definitions wich has been invalid.
@github-actions github-actions bot added the Java Pull Requests for Java binding label Oct 19, 2022
*/
public boolean isValidValue(JsonNode jsonValue) {
return isValidDefault(this, jsonValue);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 use standard method instead of static (it may replace private static boolean isValidDefault in near future), and avoid this long switch/case on schema/type.
About default value on union type, I wonder if it couldn't be even better to change logic and get the first compatible Schema of union with the value (And throw exception if none) ?
I did this code in local (and partially copy yours), and it seems to work fine (at least for unit test). I will put more details in linked JIRA Ticket in few minutes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx for the feedback, can u give me some points what standard method you are talking about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just was able to take a look at your PR. It looks like a even better solution, because it "fixes" the problem on a lower level.

Would you say that this PR is now obsolete?

Copy link
Contributor

Choose a reason for hiding this comment

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

standard method => i would say "non static overridable method" (better for object programming).
For 2 PR of 2 solution, I think we should discuss about that on the JIRA issue, i may missed some point (i want advice of other developer).

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any possible way we can rewrite this without adding or exposing the isValidValue(JsonNode ...) method?

There was a reason the isValidDefault method is private: we really don't want to be exposing the jackson internals in public methods and (if I remember correctly). There was a fair amount of work deleting these methods in the past, in order to one day replace the jackson internals.

If anyone has a better memory than me, please feel to chime in!

*/
public boolean isValidValue(JsonNode jsonValue) {
return isValidDefault(this, jsonValue);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any possible way we can rewrite this without adding or exposing the isValidValue(JsonNode ...) method?

There was a reason the isValidDefault method is private: we really don't want to be exposing the jackson internals in public methods and (if I remember correctly). There was a fair amount of work deleting these methods in the past, in order to one day replace the jackson internals.

If anyone has a better memory than me, please feel to chime in!

@RyanSkraba
Copy link
Contributor

Just to link these two ideas together: @clesaec 's proposal is at #1922

@RyanSkraba
Copy link
Contributor

This is my big question. Is the reflection serialization documented anywhere?

The best documentation for the reflection annotations is currently the Javadoc. Hopefully the new website will draw contributors to improve this situation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java Pull Requests for Java binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants