From 5e36bc5e22c97f830d6298d939d176e7d1b39af7 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Tue, 20 Sep 2022 20:13:04 +0900 Subject: [PATCH 1/2] Use As.EXISTING_PROPERTY not to generate JSON with duplicate keys --- .../bot/model/narrowcast/recipient/Recipient.java | 2 +- .../java/com/linecorp/bot/model/NarrowcastTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/line-bot-model/src/main/java/com/linecorp/bot/model/narrowcast/recipient/Recipient.java b/line-bot-model/src/main/java/com/linecorp/bot/model/narrowcast/recipient/Recipient.java index 4e1fad1d1..dfab1690c 100644 --- a/line-bot-model/src/main/java/com/linecorp/bot/model/narrowcast/recipient/Recipient.java +++ b/line-bot-model/src/main/java/com/linecorp/bot/model/narrowcast/recipient/Recipient.java @@ -21,7 +21,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; -@JsonTypeInfo(use = Id.NAME, property = "type") +@JsonTypeInfo(use = Id.NAME, property = "type", include = JsonTypeInfo.As.EXISTING_PROPERTY) @JsonSubTypes({ @JsonSubTypes.Type(AudienceRecipient.class), @JsonSubTypes.Type(LogicalOperatorRecipient.class), diff --git a/line-bot-model/src/test/java/com/linecorp/bot/model/NarrowcastTest.java b/line-bot-model/src/test/java/com/linecorp/bot/model/NarrowcastTest.java index a42ce5704..9630d4ece 100644 --- a/line-bot-model/src/test/java/com/linecorp/bot/model/NarrowcastTest.java +++ b/line-bot-model/src/test/java/com/linecorp/bot/model/NarrowcastTest.java @@ -78,6 +78,18 @@ public void testRecipientDeserializeAudience() throws JsonProcessingException { assertThat(((AudienceRecipient) recipient).getAudienceGroupId()).isEqualTo(59693); } + @Test + public void testRecipientSerializeAudience() throws JsonProcessingException { + ObjectMapper objectMapper = ModelObjectMapper.createNewObjectMapper(); + String content = "{\"audienceGroupId\":59693,\"type\":\"audience\"}"; + Recipient recipient = objectMapper.readValue( + content, + Recipient.class); + assertThat(recipient).isInstanceOf(AudienceRecipient.class); + String json = objectMapper.writeValueAsString(recipient); + assertThat(json).isEqualTo(content); + } + @Test public void testRecipientDeserializeOperator() throws JsonProcessingException { ObjectMapper objectMapper = ModelObjectMapper.createNewObjectMapper(); From ca857dab5f9f30863b64d32e70605332d15ab1c6 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Tue, 20 Sep 2022 20:52:59 +0900 Subject: [PATCH 2/2] empty commit to run actions again