By no means am I a Jackon / JSON master, which is probably obvious from the following problem that I am facing:
I have two possible data structures that I receive. The first is called amountTransaction:
{ "amountTransaction": { "clientCorrelator":"54321", "endUserId":"tel:+16309700001" } }
which is represented by the following Java object:
@JsonIgnoreProperties(ignoreUnknown = true) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName(value = "amountTransaction") @JsonInclude(JsonInclude.Include.NON_NULL) public class AmountTransaction { private String clientCorrelator; private String endUserId; ... }
However, the amountTransaction object is also displayed as a child of the paymentTransactionNotification object:
{ "paymentTransactionNotification": { "amountTransaction": { "clientCorrelator": "54321", "endUserId": "tel:+16309700001" } } }
.. which I thought would be presented:
@JsonIgnoreProperties(ignoreUnknown = true) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) @JsonTypeName(value = "paymentTransactionNotification") @JsonInclude(JsonInclude.Include.NON_NULL) public class PaymentTransactionNotification { private AmountTransaction amountTransaction; ... }
Parsing JSON using the amountTransaction object works fine. This is a fairly simple example of WRAPPER_OBJECT.
However, when trying to parse the JSON for paymentTransactionNotification, I get an exception indicating that it cannot correctly process the transaction value as an element of the paymentTransactionNotification parameter:
com.fasterxml.jackson.databind.JsonMappingException: Could not resolve type id 'clientCorrelator' into a subtype of [simple type, class com.sf.oneapi.pojos.AmountTransaction]
Any thoughts on how I can properly annotate this so that my code can correctly handle both standalone and encapsulated transaction amount objects?
java json jackson wrapper
uncrase
source share