У меня проблема с десериализацией следующего json
{
"GrpHdr": {
"MsgId": "Message-1",
"CreDtTm": "2018-03-02T10:15:30+01:00[Europe/Paris]",
"NbOfTxs": "1",
"InitgPty": {
"Nm": "Remitter"
}
},
"PmtInf": [
{
"PmtInfId": "1"
},
{
"PmtInfId": "2"
}
]
}
Я создал класс MixIn:
открытый абстрактный класс CustomerCreditTransferInitiationMixIn {public PaymentInstructions paymentInstructions;
@JsonCreator
public CustomerCreditTransferInitiationMixIn(
@JsonProperty("GrpHdr") GroupHeader GrpHdr,
@JsonProperty("PmtInf") List<PaymentInstruction> PmtInf
) {
this.paymentInstructions = PaymentInstructions.valueOf(PmtInf);
}
@JsonProperty("GrpHdr")
abstract GroupHeader getGroupHeader();
@JsonProperty("PmtInf")
abstract List<PaymentInstruction> getPaymentInstructions();
}
У меня нет проблем с десериализацией заголовка группы в этом случае.Картирование разных имен.Но в случае с PmtInf я запутался.Это список, который я хочу десериализовать в Список платежных инструкций.Но PmtInf - это система оплаты.
Я создал тест:
@Test
public void JacksonMixinAnnotationTestJsonIsoFileFromTester() throws JsonProcessingException, Throwable {
CustomerCreditTransferInitiation customerCreditTransferInitiation;
String jsonFile = "testWithShortNames";
InputStream inputStream = new ClassPathResource(jsonFile + ".json").getInputStream();
ObjectMapper objectMapper = buildMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.registerModule(new JavaTimeModule());
objectMapper.addMixIn(CustomerCreditTransferInitiation.class, CustomerCreditTransferInitiationMixIn.class);
objectMapper.addMixIn(GroupHeader.class, GroupHeaderMixIn.class);
objectMapper.addMixIn(PaymentInstruction.class, PaymentInstructionMixIn.class);
objectMapper.addMixIn(PartyIdentification.class, PartyIdentificationMixIn.class);
customerCreditTransferInitiation = objectMapper.readValue(inputStream, CustomerCreditTransferInitiation.class);
//GroupHeader
Assert.assertNotNull(customerCreditTransferInitiation.getGroupHeader());
Assert.assertNotNull(customerCreditTransferInitiation.getGroupHeader().getMessageId());
Assert.assertNotNull(customerCreditTransferInitiation.getGroupHeader().getCreationDateTime());
Assert.assertNotNull(customerCreditTransferInitiation.getGroupHeader().getNumberOfTransactions());
Assert.assertNotNull(customerCreditTransferInitiation.getGroupHeader().getInitiatingParty());
Assert.assertNotNull(customerCreditTransferInitiation.getGroupHeader().getInitiatingParty().getName());
//PaymentInstructions
Assert.assertNotNull(customerCreditTransferInitiation.getPaymentInstructions());}
Получаю следующую ошибку:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: нераспознанное поле «PmtInfId» (класс com.seb.payment.iso.domain.PaymentInstruction), не помеченное как игнорируемое (19 известных свойств:"," debtorAgent "," manualForDebtorAgent "," numberOfTransactions "," requestExecutionTime "," debtorAccount "," creditTransferTransactions "," debtorAgentAccount "," batchBooking "," poolingAdjustmentDate "," ultimateDebtor ", "charge""chargeAccount", "chargeAccountAgent"]) в [Источник: НЕИЗВЕСТНО;строка: -1, столбец: -1] (через цепочку ссылок: com.seb.payment.iso.domain.CustomerCreditTransferInitiation ["PmtInf"] -> com.seb.payment.iso.domain.PaymentInstruction ["PmtInfId"])