XChange icon indicating copy to clipboard operation
XChange copied to clipboard

[Core] Fixing an issue with UserTrades serialization/deserialization

Open makarid opened this issue 2 years ago • 3 comments

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.

makarid avatar Jul 12 '22 16:07 makarid

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

walec51 avatar Jul 13 '22 06:07 walec51

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: @.***>

makarid avatar Jul 13 '22 08:07 makarid

I have put the JsonIgnore and it works.Can you please check it.Thanks

makarid avatar Jul 20 '22 10:07 makarid