fairyto2 opened a new pull request, #2474:
URL: https://github.com/apache/avro/pull/2474
### What is the purpose of the change
This pull request aims to enhance the functionality of Union types in the
Java language by enabling the setting of default values for any type within a
Union. Currently, only the first type in a Union can have a default value. This
change will make Union types more flexible and versatile in Java programming.
Proposed Changes
Modification of Union Type Declaration
Previously, Union types in Java allowed setting default values only for the
first type in the Union. This restriction is being lifted to enable default
values for any type within the Union. This change will require modifications to
the grammar and type-checking mechanisms.
### Verifying this change
JacksonUtils.java
` public static Object toObject(JsonNode jsonNode, Schema schema) {
if (schema != null && schema.getType().equals(Schema.Type.UNION)) {
for (Schema type : schema.getTypes()) {
Object o = toObject(jsonNode, type);
if (o != null) {
return o;
}
}
}`
Schema.java
` case UNION: // check against each branch of union
for (Schema branch : schema.getTypes())
if (isValidDefault(branch, defaultValue))
return true;
return false;`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]