Skip to content

Deserialization to type BaseMoney fails #498

@Sectan

Description

@Sectan

Describe the bug
Querying price information of a product with the graphql-api results in deserialization errors:

Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class com.commercetools.graphql.api.types.BaseMoney]: missing type id property '__typename' (for POJO property 'value')

To Reproduce

public class Reproducer {

    public static void main(String[] args) {
        final ProjectApiRoot client = createApiClient();
        Logger logger = LoggerFactory.getLogger(Reproducer.class.getName());

        GraphQLResponse<ProductQueryResult> responseEntity =
                client
                        .graphql()
                        .query(GraphQL.products(q -> q.limit(8))
                                .projection(p -> p.total().results().id().masterData().current().masterVariant().prices().value().centAmount()))
                        .executeBlocking()
                        .getBody();
        responseEntity.getData().getResults().forEach(result -> {
            logger.info("Id: " + result.getId() + "Name: " + result.getMasterData().getCurrent().getName());
            logger.info("Id: " + result.getId() + "Name: " + result.getMasterData().getCurrent().getMasterVariant().getPrices());
        });
        client.close();
    }

    public static ProjectApiRoot createApiClient() {
        var projectApiRoot = ApiRootBuilder.of()
                .defaultClient(
                        ClientCredentials.of()
                                .withClientId("<CLIENT-ID>")
                                .withClientSecret("<SECRET")
                                .build(),
                        ServiceRegion.GCP_EUROPE_WEST1.getOAuthTokenUrl(),
                        ServiceRegion.GCP_EUROPE_WEST1.getApiUrl()
                )
                .build("<PROJECT-KEY>");

        return projectApiRoot;
    }
}

Expected behavior
Reproducer code should run and price information should be deserialized without an error.

Screenshots/Code snippet
Following error is thrown:
Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class com.commercetools.graphql.api.types.BaseMoney]: missing type id property '__typename' (for POJO property 'value')

Stack information (please complete the following information):

  • Java: 17
  • SDK: 16.3.0

Additional context
NA

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions