我使用Jackson ObjectMapper將字符串轉換爲Pojo。如何映射一個字符串內的對象以使用ObjectMapper設置
我收到的消息:
{
"countryCode": "US",
"skuNumber": "TEST",
"itemTaxCd": "89999",
"lastModifiedBy": "xyz"
}
方法:
public void processImsProductTaxEvents(String event) {
try {
SkuMasterDTO message = objectMapper.readValue(event, SkuMasterDTO.class);
log.debug("Received message from IMS", message);
} catch (Exception e) {
log.error("Error in Object Mapper converting String to TaxCodeDTO", e);
}
}
現在COUNTRYCODE是內內SkuMasterDTO CountryDTO定義爲一組
private Set<CountryDTO> countries = new HashSet<>();
CountryDTO類
public class CountryDTO implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull
@Size(max = 2)
private String countryCode;
我試圖將countryCode設置爲集而不更改輸入Json。有什麼建議麼?
的,你需要輸入JSON類似,'{ 「國家」:{ 「COUNTRYCODE」: 「US」}, 「skuNumber」: 「TEST」, 「itemTaxCd」: 「89999」, 「lastModifiedBy 「:」xyz「 }' – dullpointer
客戶端以這種格式發送它,所以我不想在他們的結尾要求改變。 –