From c8cfa50de653098d9a55e09779814c21e9915a7f Mon Sep 17 00:00:00 2001 From: nkramer44 Date: Sat, 2 Nov 2024 17:57:19 -0400 Subject: [PATCH] cleanup --- .../TransactionResultDeserializer.java | 4 +++ .../xrpl4j/model/transactions/AmmBid.java | 3 --- .../model/transactions/Transaction.java | 1 - .../transactions/json/UnlModifyJsonTests.java | 25 +++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionResultDeserializer.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionResultDeserializer.java index 932a9f277..9bf99d3be 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionResultDeserializer.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/jackson/modules/TransactionResultDeserializer.java @@ -75,7 +75,11 @@ public TransactionResult deserialize(JsonParser jsonParser, DeserializationCo Optional metadata = getTransactionMetadata(objectMapper, objectNode); UnsignedLong closeDate = objectNode.has("date") ? UnsignedLong.valueOf(objectNode.get("date").asLong()) : null; + // The Transaction is @JsonUnwrapped in TransactionResult, which means these fields + // get added to the Transaction.unknownFields Map. To prevent that, we simply remove them from the JSON, because + // they should only show up in AccountTransactionsTransaction objectNode.remove(EXTRA_TRANSACTION_FIELDS); + JavaType javaType = objectMapper.getTypeFactory().constructType(new TypeReference() { }); T transaction = objectMapper.convertValue(objectNode, javaType); diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmBid.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmBid.java index 3bc9261d1..4f3e539fe 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmBid.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/AmmBid.java @@ -110,7 +110,4 @@ default TransactionFlags flags() { @JsonProperty("AuthAccounts") List authAccounts(); - /*@Override - @JsonAnyGetter - Map unknownFields();*/ } diff --git a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/Transaction.java b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/Transaction.java index fb96cd14a..ef0f43e38 100644 --- a/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/Transaction.java +++ b/xrpl4j-core/src/main/java/org/xrpl/xrpl4j/model/transactions/Transaction.java @@ -227,7 +227,6 @@ default PublicKey signingPublicKey() { Optional networkId(); @JsonAnyGetter - @JsonInclude(Include.NON_ABSENT) Map unknownFields(); } diff --git a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/UnlModifyJsonTests.java b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/UnlModifyJsonTests.java index 3226642b2..367abc7b8 100644 --- a/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/UnlModifyJsonTests.java +++ b/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/model/transactions/json/UnlModifyJsonTests.java @@ -56,4 +56,29 @@ public void testJson() throws JsonProcessingException, JSONException { assertCanSerializeAndDeserialize(unlModify, json); } + + @Test + public void testJsonWithUnknownFields() throws JsonProcessingException, JSONException { + UnlModify unlModify = UnlModify.builder() + .fee(XrpCurrencyAmount.ofDrops(12)) + .sequence(UnsignedInteger.valueOf(2470665)) + .ledgerSequence(LedgerIndex.of(UnsignedInteger.valueOf(67850752))) + .unlModifyValidator("EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539") + .unlModifyDisabling(UnsignedInteger.valueOf(1)) + .putUnknownFields("Foo", "Bar") + .build(); + + String json = "{" + + " \"Foo\" : \"Bar\",\n" + + "\"Account\":\"" + UnlModify.ACCOUNT_ZERO + "\"," + + "\"Fee\":\"12\"," + + "\"LedgerSequence\":67850752," + + "\"Sequence\":2470665," + + "\"SigningPubKey\":\"\"," + + "\"TransactionType\":\"UNLModify\"," + + "\"UNLModifyDisabling\":1," + + "\"UNLModifyValidator\":\"EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539\"}"; + + assertCanSerializeAndDeserialize(unlModify, json); + } }