Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nkramer44 committed Nov 2, 2024
1 parent 6251706 commit c8cfa50
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public TransactionResult<T> deserialize(JsonParser jsonParser, DeserializationCo
Optional<TransactionMetadata> 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>() {
});
T transaction = objectMapper.convertValue(objectNode, javaType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,4 @@ default TransactionFlags flags() {
@JsonProperty("AuthAccounts")
List<AuthAccountWrapper> authAccounts();

/*@Override
@JsonAnyGetter
Map<String, Object> unknownFields();*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ default PublicKey signingPublicKey() {
Optional<NetworkId> networkId();

@JsonAnyGetter
@JsonInclude(Include.NON_ABSENT)
Map<String, Object> unknownFields();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit c8cfa50

Please sign in to comment.