jansupol / jsonbapi

0 stars 0 forks source link

Confusion about JsonbNillable default value #74

Open jansupol opened 6 years ago

jansupol commented 6 years ago

Quoting from Javadoc of annotation JsonbNillable:

In case of false, fields will not be serialized (default behaviour).

This sounds as if the default value of the annotation is false. However, the actual default value is true:

boolean value() default true;

Maybe the "default behaviour" refers to property serialization when no JsonbNillable annotation is present at class level, but this is rather confusing to the reader.

Moreover, it is not quite clear which of JsonbNillable and JsonbProperty takes precedence. Consider this example:

@JsonbNillable
public void Foo {

     @JsonbProperty("the_value")
     private String theValue;
}

Running a test with Yasson shows that the nillable = false default of JsonbProperty takes precedence over the class level annotation. This complies with Section 4.3 of the spec, but this behaviour cannot be gathered from the Javadoc of the two annotation classes.

jansupol commented 6 years ago
jansupol commented 6 years ago

@m0mus Commented It's an error in javadoc. It should say:

In case of true, fields will not be serialized (default behaviour).

The general rule is that smaller scope annotation takes precedence over the bigger scope annotation. So , it you case @JsonbProperty on field overrides @JsonbNillable on type.