From 47034b227574ffa4a995561e0548121835c958dc Mon Sep 17 00:00:00 2001 From: Aleksey Chubarev Date: Thu, 23 Jun 2022 14:15:40 +0300 Subject: [PATCH] BillResponse supports unknown json fields; RequestMappingIntercessorTest added --- .../sdk/model/out/BillResponse.java | 25 +++++----- .../client/RequestMappingIntercessorTest.java | 47 +++++++++++++++++++ 2 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 src/test/java/com/qiwi/billpayments/sdk/client/RequestMappingIntercessorTest.java diff --git a/src/main/java/com/qiwi/billpayments/sdk/model/out/BillResponse.java b/src/main/java/com/qiwi/billpayments/sdk/model/out/BillResponse.java index 69f7131..cd14f8d 100644 --- a/src/main/java/com/qiwi/billpayments/sdk/model/out/BillResponse.java +++ b/src/main/java/com/qiwi/billpayments/sdk/model/out/BillResponse.java @@ -1,13 +1,14 @@ package com.qiwi.billpayments.sdk.model.out; +import java.time.ZonedDateTime; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.qiwi.billpayments.sdk.model.MoneyAmount; import com.qiwi.billpayments.sdk.model.in.CustomFields; import com.qiwi.billpayments.sdk.model.in.Customer; -import java.time.ZonedDateTime; - +@JsonIgnoreProperties(ignoreUnknown = true) public class BillResponse { private final String siteId; private final String billId; @@ -22,16 +23,16 @@ public class BillResponse { @JsonCreator public BillResponse( - @JsonProperty("siteId") String siteId, - @JsonProperty("billId") String billId, - @JsonProperty("amount") MoneyAmount amount, - @JsonProperty("status") ResponseStatus status, - @JsonProperty("comment") String comment, - @JsonProperty("customer") Customer customer, - @JsonProperty("creationDateTime") ZonedDateTime creationDateTime, - @JsonProperty("expirationDateTime") ZonedDateTime expirationDateTime, - @JsonProperty("payUrl") String payUrl, - @JsonProperty("customFields") CustomFields customFields + @JsonProperty(value = "siteId", required = true) String siteId, + @JsonProperty(value = "billId", required = true) String billId, + @JsonProperty(value = "amount", required = true) MoneyAmount amount, + @JsonProperty(value = "status", required = true) ResponseStatus status, + @JsonProperty(value = "comment", required = true) String comment, + @JsonProperty(value = "customer", required = true) Customer customer, + @JsonProperty(value = "creationDateTime", required = true) ZonedDateTime creationDateTime, + @JsonProperty(value = "expirationDateTime", required = true) ZonedDateTime expirationDateTime, + @JsonProperty(value = "payUrl", required = true) String payUrl, + @JsonProperty(value = "customFields", required = true) CustomFields customFields ) { this.siteId = siteId; this.billId = billId; diff --git a/src/test/java/com/qiwi/billpayments/sdk/client/RequestMappingIntercessorTest.java b/src/test/java/com/qiwi/billpayments/sdk/client/RequestMappingIntercessorTest.java new file mode 100644 index 0000000..90af047 --- /dev/null +++ b/src/test/java/com/qiwi/billpayments/sdk/client/RequestMappingIntercessorTest.java @@ -0,0 +1,47 @@ +package com.qiwi.billpayments.sdk.client; + +import org.junit.Assert; +import org.junit.Test; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.qiwi.billpayments.sdk.json.ObjectMapperFactory; +import com.qiwi.billpayments.sdk.model.out.BillResponse; + +public class RequestMappingIntercessorTest { + @Test + public void testDeserializeResponseBody() throws JsonProcessingException { + //given + ObjectMapper mapper = ObjectMapperFactory.create(); + String extendedBillResponseBody = "{\n" + + " \"siteId\": \"opeqvd-00\",\n" + + " \"billId\": \"6c2b25e2-f2cc-11ec-a498-00155d15bac7\",\n" + + " \"amount\": {\n" + + " \"currency\": \"RUB\",\n" + + " \"value\": \"1.00\"\n" + + " },\n" + + " \"status\": {\n" + + " \"value\": \"WAITING\",\n" + + " \"changedDateTime\": \"2022-06-23T11:13:54.854+03:00\"\n" + + " },\n" + + " \"customer\": {\n" + + " \"email\": \"test@qiwi.com\",\n" + + " \"account\": \"accountId\",\n" + + " \"phone\": \"79876543210\"\n" + + " },\n" + + " \"customFields\": {\n" + + " \"apiClient\": \"java_sdk\",\n" + + " \"apiClientVersion\": \"1.5.0\"\n" + + " },\n" + + " \"comment\": \"comment\",\n" + + " \"creationDateTime\": \"2022-06-23T11:13:54.854+03:00\",\n" + + " \"expirationDateTime\": \"2022-06-24T11:13:54.369+03:00\",\n" + + " \"payUrl\": \"https://some.url.com\",\n" + + " \"recipientPhoneNumber\": \"79876543210\",\n" + + " \"field\": \"shouldBeIgnored\"\n" + + "}"; + + //expected: "no exception thrown" + BillResponse response = mapper.readValue(extendedBillResponseBody, BillResponse.class); + Assert.assertNotNull(response); + } +} \ No newline at end of file