-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
Add AvroGenerator.Feature.ADD_NULL_AS_DEFAULT_VALUE_IN_SCHEMA
for adding default null
in generated schema
#145
Comments
@kucera-jan-cz Could you include bit more information on code you are using: I assume you have a simple POJO definition (class |
@cowtowncoder Hello and thanks for your reply.
|
Have you tried using |
@kucera-jan-cz I meant Jackson code used to produce output that is missing "default" entry. I am not sure I fully understand exact steps of desired Jackson dataformat solution. |
Oh, I see what you're asking. Currently, Jackson will generate unions for optional fields: package dummy;
public class PersonV1 {
public PersonV1(String age) {
this.age = age;
}
private String age;
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
} Plus AvroMapper mapper = new AvroMapper();
System.out.println(mapper.schemaFor(mapper.constructType(PersonV1.class)).getSchema() gives
But it doesn't generate defaults unless explicitly given one with |
Thanks for your response @cowtowncoder and @baharclerode. Yes it's exactly as you mentioned in your last post - the only missing part is to enable adding Regards |
AvroGenerator.Feature.ADD_NULL_AS_DEFAULT_VALUE_IN_SCHEMA
for adding default null
in generated schema
PR merged, so this is now in for 3.0.0 (and if someone has time & itch, possibly backport in 2.x, currently 2.10). |
Hello,
currently we are using for generation schema from POJO ReflectData.AllowNull.get() however we would like to switch to jackson-dataformats-binary. The only issue with the switch is absence of "default" value in schema (which we currently have in our schema registry and would break our compatibility). Is it possible to set this behavior through AvroFactory or AvroSchemaGenerator?
For clarification here is example from jackson-dataformats-binary:
{"type":"record","name":"PersonV1","namespace":"dummy","fields":[{"name":"age","type":["null","string"]}]}
And here example from ReflectData.AllowNull.get():
{"type":"record","name":"PersonV1","namespace":"dummy","fields":[{"name":"age","type":["null","string"],"default":null}]}
Thanks in advance for your answer
The text was updated successfully, but these errors were encountered: