我使用的是傑克遜2.7.0如何忽略某些領域與傑克遜的ObjectMapper.readerForUpdating
我試圖忽視encodingType
更新了一些新值的現有對象時:
ObjectMapper om = new ObjectMapper();
om.readerForUpdating(message).readValue(messageSubset);
message
包含值爲encodingType
。
messageSubset
(JSON字符串)不包含encodingType
的條目(無鍵值)。
我已經試過:
- 對於ObjectMapper:
om.setSerializationInclusion(Include.NON_EMPTY);
- 在消息類:
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonIgnoreProperties(value = { "encodingType" })
@JsonInclude(Include.NON_EMPTY)
@JsonInclude(Include.NON_NULL)
- 在現場和getter/setter方法:
@JsonInclude(Include.NON_EMPTY)
@JsonInclude(Include.NON_NULL)
@JsonIgnore
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
非上述工作!任何幫助?
我想這與readerForUpdating和/或其中一個正在更新的事實有關。
我剛剛試過你的代碼與虛擬'消息'類其中'encodingType'是一個'字符串',它工作正常。不需要註釋。你可以發佈'message'類和一個JSON例子的代碼嗎? –
我通過像下面這樣通過配置ObjectMapper解決了這個問題: 'om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);' 'om.configure(DeserializationFeature。FAIL_ON_UNKNOWN_PROPERTIES,FALSE);' 'om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES,FALSE);' 而上的消息類爲正確的屬性: '@ JsonIgnore'上的setter '@ JsonProperty'在吸氣劑上 –