stil4m / mollie-api

Mollie API for Java
14 stars 14 forks source link

LazyDecompressingInputStream as result from unrecognized property 'links' #2

Closed sjdmulde closed 8 years ago

sjdmulde commented 8 years ago

Hello,

When executing the following code:

ResponseOrError paymentStatus = mollie.getPaymentStatus(mollieApiKey, gateWayReference);

i get the exception:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "first" (class nl.stil4m.mollie.domain.Links), not marked as ignorable (3 known properties: , "webhookUrl", "paymentUrl", "redirectUrl"])
 at [Source: org.apache.http.client.entity.LazyDecompressingInputStream@1a4ebd0e; line: 1, column: 4362] (through reference chain: nl.stil4m.mollie.domain.Links["first"])
    at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:79)
    at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:579)
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:672)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:906)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperties(BeanDeserializerBase.java:926)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:625)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObjectUsingNonDefault(BeanDeserializer.java:393)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:289)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:375)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:559)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObjectUsingNonDefault(BeanDeserializer.java:393)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:289)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2796)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1988)
    at nl.stil4m.mollie.DynamicClient.deserialize(DynamicClient.java:67)
    at nl.stil4m.mollie.DynamicClient.lambda$executeRequest$2(DynamicClient.java:59)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:222)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:139)
    at nl.stil4m.mollie.DynamicClient.executeRequest(DynamicClient.java:55)
    at nl.stil4m.mollie.DynamicClient.getPaymentStatus(DynamicClient.java:44)
    at nl.stil4m.mollie.Client.getPaymentStatus(Client.java:25)

This is probably due to the fact that the mollie api (https://www.mollie.com/be/docs/reference/payments/list) has a links result:

"links": {
        "first": "https://api.mollie.nl/v1/payments?count=10&offset=0",
        "previous": null,
        "next": "https://api.mollie.nl/v1/payments?count=10&offset=10",
        "last": "https://api.mollie.nl/v1/payments?count=10&offset=270"
    }

This is mapped in Java to the links class: private nl.stil4m.mollie.domain.Links links which does not correspond to the api result:

public class Links {
    private final java.lang.String paymentUrl;
    private final java.lang.String redirectUrl;
    private final java.lang.String webhookUrl;

  ......
}

Regards, Stijn

stil4m commented 8 years ago

Hi Stijn,

Thanks for the report. I think Mollie changed their API a bit. I will look into it tonight or if you want you can create a PR.

sjdmulde commented 8 years ago

Hey,

I found the cause of the issue. It appears when you test the webhook with mollie, they send an empty id.

So when you call the method

public ResponseOrError<PaymentStatus> getPaymentStatus(String apiKey, String id) throws IOException {
    HttpGet httpGet = new HttpGet(endpoint + "/payments/" + id);
    return executeRequest(apiKey, httpGet, PaymentStatus.class);
}

with an empty id, it actually calls a different api and thus the error. I think it would be wise to check if the id is not empty.

All in all good news, the api works with the existing Java code.

Regards, Stijn

stil4m commented 8 years ago

Thanks. I'll create a new ticket to verify the presence of the payment identifier and to add client calls to list payments.