Missing Required Creator Property? Jackson-Databind 2.6.3+

4,143 views
Skip to first unread message

Shack

unread,
Mar 30, 2016, 6:00:20 PM3/30/16
to jackson-user
I am trying to map json to a custom object using the code below.
It works just fine in Jackson-Databind 2.5.4 and below, but in  Jackson-Databind 2.6.3+ it throws the error:
com.fasterxml.jackson.databind.JsonMappingException: Missing required creator property 'Subject' (index 3)

I tried adding

disable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES);
but it's as though it has no effect.


I've searched everywhere and stepped through the code and can't figure out why it's not working.

Any help would be great!


Message:

public class Message
{
  private final String Type;
  private final String MessageId;
  private final String Subject;

  @java.beans.ConstructorProperties({ "Type", "MessageId", "Subject" })
  public Message(final String Type, final String MessageId, final String Subject)
  {
    this.Type = Type;
    this.MessageId = MessageId;
    this.Subject = Subject;
  }

  public String getType()
  {
    return this.Type;
  }

  public String getMessageId()
  {
    return this.MessageId;
  }

  public String getSubject()
  {
    return this.Subject;
  }
}


Mapper:


public final class MessageMapper extends ObjectMapper
{

  public MessageMapper()

  {

    disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

    disable(SerializationFeature.INDENT_OUTPUT);

    disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

    // disable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES);

    enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);

    enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

    setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);

    setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);

    setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.ANY);

    setSerializationInclusion(JsonInclude.Include.ALWAYS);

    registerModule(new JodaModule());

    registerModule(new GuavaModule());

    setAnnotationIntrospector(new ConstructorPropertiesAnnotationIntrospector());

  }

}


Code throwing the error:

MessageMapper mapper = new MessageMapper();
final Message body = mapper.readValue(json, Message.class); //Where json is the Json string to be parsed.


Json Objects:

object1:     {"Type":"Notify", "MessageId":"1234567890", "Subject":"Topic1"}
object2:     {"Type":"Notify", "MessageId":"0987654321"}





Tatu Saloranta

unread,
Mar 31, 2016, 8:12:17 PM3/31/16
to jackson-user
Does this also fail on 2.7(.3)?

I didn't think 2.6 actually supports `@java.beans.ConstructorProperties` (2.7 does), but whatever detects it seems to indicate properties as `required` -- and this is what exception is about. Although `DeserializationFeature` has similar name, it is not directly related.

-+ Tatu +-


--
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 jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages