XChange
XChange copied to clipboard
[Core] Fixing an issue with UserTrades serialization/deserialization
Hello, everyone there is a issue with UserTrades class when someone wants to parse it to json and then deserialize it again. If you run the below code you will see that even though the List<UserTrade> has 1 element, the deserialization creates the UserTrades class with 2 elements (dublicate the element). The issue is fixing when i rename the getUserTrades() method to userTrades(). If you have a better solution please tell me in order to implement it.
String userTradesString = new ObjectMapper().writeValueAsString(new UserTrades( List.of(new UserTrade.Builder().build()), Trades.TradeSortType.SortByTimestamp)); System.out.println(userTradesString); UserTrades userTrades = new ObjectMapper().readValue(userTradesString, UserTrades.class); System.out.println(userTrades.userTrades());
I have also corrected the timestamp on adaptUserTrades on FtxStreamingExchangeAdapter in order to have the time of the exchange.
changing our API to make jackson serialization work?
you can use @JsonIgnore on getUserTrades
you can also write you own deserializer
also add an unit test if you want protect this feature from future bugs
Ok, I will do that.
On Wed, Jul 13, 2022, 9:21 AM Adam Walczak @.***> wrote:
changing our API to make jackson serialization work?
you can use @JsonIgnore https://github.com/JsonIgnore on getUserTrades
— Reply to this email directly, view it on GitHub https://github.com/knowm/XChange/pull/4527#issuecomment-1182813907, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHIWQ73D4EW37RDU2YZ4A7DVTZOAJANCNFSM53LSQXSQ . You are receiving this because you authored the thread.Message ID: @.***>
I have put the JsonIgnore and it works.Can you please check it.Thanks