Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiquidityPoolIDDeserializer is missing from the PageDeserializer. #422

Merged

Conversation

vinamogit
Copy link
Contributor

LiquidityPoolIDDeserializer is missing from the PageDeserializer.

This fixes #404 and #421.

@vinamogit vinamogit changed the title Fix #404 and #421 LiquidityPoolIDDeserializer is missing from the PageDeserializer. May 1, 2022
@vinamogit vinamogit force-pushed the fix-lp-id-deserialization-in-page branch from aae1186 to 59d1a06 Compare May 1, 2022 20:49
@@ -17,6 +19,16 @@ public void testDeserialize() {
assertEquals(accountsPage.getLinks().getPrev().getHref(), "/accounts?order=desc&limit=10&cursor=1");
assertEquals(accountsPage.getLinks().getSelf().getHref(), "/accounts?order=asc&limit=10&cursor=");
}

@Test
public void testDeserializeWithLiquidityPoolBalance() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great test coverage, do you think also worth adding one more check on regression aspect, i.e.:

assertEquals(accountsPage.getRecords().get(0).getBalances()[1].getLiquidityPoolID(), Optional.absent());

style-wise, good to remove the extra lines.

@@ -45,6 +46,7 @@ public Page<E> deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo
.registerTypeAdapter(EffectResponse.class, new EffectDeserializer())
.registerTypeAdapter(LiquidityPoolResponse.class, new LiquidityPoolDeserializer())
.registerTypeAdapter(TransactionResponse.class, new TransactionDeserializer())
.registerTypeAdapter(LiquidityPoolID.class, new LiquidityPoolIDDeserializer())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I see the same type adapter registration for LiquidityPoolID done up at the main gson instance used by all response handlers:

https://github.com/vinamogit/java-stellar-sdk/blob/fix-lp-id-deserialization-in-page/src/main/java/org/stellar/sdk/responses/GsonSingleton.java#L39

Do you know why this is not getting used by gson to resolve the LiquidityPoolID in TradeResponse during unmarshaling? It looks TradesRequestBuilder.execute uses the ResponseHandler which in turn uses that gson instance which includes the type registration. If re-registering here at page deser is needed, so be it, nice find!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know anything about Gson, my guess is that it's either because of generic type or because a new Gsonbuilder is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that there are several Gson instances, each need to know the deserializers.
We could avoid the double maintenance between GsonSingleton and PageDeserializer by using the JsonAdapter annotation on all the types which are not Page.

The only type that would need to be registered with both GsonBuilders will be the TransactionDeserializer since it uses a third instance of Gson to reconciliate the memo with its memo_type.

I published a branch for comparison:
vinamogit@fe9c9de

@vinamogit vinamogit force-pushed the fix-lp-id-deserialization-in-page branch from 59d1a06 to f3e98d5 Compare May 3, 2022 20:48
@sreuland sreuland merged commit 4506bd6 into lightsail-network:master May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GSON parse error when fetching accounts by trustline
2 participants