Hi all,

Since I switched from Jackson 2.8.7 to 2.9.2, serializing a class, which 
does not specify a @JsonTypeName like in this example:

  @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = 
JsonTypeInfo.As.PROPERTY, property = "_type")
  @JsonTypeIdResolver(CustomTypeNameIdResolver.class)
  public class BaseClassWithoutJsonTypeName {
    public boolean b;
  }


leads to the following JSON output:

{"type":"null","b":true}

Remark: The CustomTypeNameIdResolver returns null if no @JsonTypeName 
annotation can be found on the class.


Using Jackson 2.8.7 the JSON output was:

{"b":true}


Looking at the sourcecode I found the following piece of code in 2.8.7:

AsPropertyTypeSerializer:
    @Override
    public void writeTypePrefixForObject(Object value, JsonGenerator jgen) 
throws IOException
    {
        final String typeId = idFromValue(value);
        if (typeId == null) {
            jgen.writeStartObject();
        } else if (jgen.canWriteTypeId()) {
            jgen.writeTypeId(typeId);
            jgen.writeStartObject();
        } else {
            jgen.writeStartObject();
            jgen.writeStringField(_typePropertyName, typeId);
        }
    }

It seems like this class was refactored on the way to version 2.9.2, since 
I could not found a corresponding null-check in 2.9.2.

Was this change in writing "null" values for type properties on purpose? Is 
there a way to get the old behaviour back?

Regards,
Paolo


-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to