相关文章推荐
活泼的金针菇  ·  Excel VBA ...·  1 年前    · 
傲视众生的佛珠  ·  Android Studio (AVD) ...·  1 年前    · 
爱吹牛的瀑布  ·  ab01edf62286 - 简书·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm using Jackson 2.7.0

I'm trying to ignore encodingType when updating an existing object with some new values:

ObjectMapper om = new ObjectMapper();
om.readerForUpdating(message).readValue(messageSubset);

message contains a value for encodingType.
messageSubset (JSON-string) does not contain an entry (no key-value) for encodingType.

What I've tried:

  • For the ObjectMapper:
  • om.setSerializationInclusion(Include.NON_EMPTY);
  • On the message class:
  • @JsonIgnoreProperties(ignoreUnknown = true)
  • @JsonIgnoreProperties(value = { "encodingType" })
  • @JsonInclude(Include.NON_EMPTY)
  • @JsonInclude(Include.NON_NULL)
  • On the field and on the getters/setters:
  • @JsonInclude(Include.NON_EMPTY)
  • @JsonInclude(Include.NON_NULL)
  • @JsonIgnore
  • @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
  • Non of the above work! Any help?
    I suppose this has something to do with readerForUpdating and/or the fact that one of them is being updated.

    I've just tried your code with a dummy Message class where encodingType is a String and it works fine. No annotations needed. Could you post the code for class of message and an example JSON ? – Manos Nikolaidis Mar 7, 2016 at 15:13 I fixed the problem by configering the ObjectMapper like this: om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false); And on the Message class for the correct properties: @JsonIgnore on the setter @JsonProperty on the getter – Thomas Stubbe Mar 8, 2016 at 10:22

    I fixed the problem by configuring the ObjectMapper like this (not sure if these are all needed though):

    om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);

    And on the Message class for the properties needed:

    @JsonIgnore on the setter (excludes it when parsing to the Java object)
    @JsonProperty on the getter (includes it when parsing to the JSON object)

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.