0

I am consuming the public API for crypto currencies in Mexico: https://api.bitso.com/v3/available_books/ that returns a json like this one:

    "success": true,
    "payload": [
        {
            "book": "btc_mxn",
            "minimum_price": "500.00",
            "maximum_price": "16000000.00",
            "minimum_amount": "0.000075",
            "maximum_amount": "500.00000000",
            "minimum_value": "5",
            "maximum_value": "10000000.00"
        },
        {
            "book": "eth_btc",
            "minimum_price": "0.00000100",
            "maximum_price": "5000.00000000",
            "minimum_amount": "0.00000100",
            "maximum_amount": "1000.00000000",
            "minimum_value": "0.00000100",
            "maximum_value": "2000.00000000"
        },

and the code that consumes it with Webclient is:

    @Override
    public Mono<Coins> getCoins() {
        return webClient.get().uri("https://api.bitso.com/v3/available_books/")
                .accept(MediaType.APPLICATION_JSON)
                .retrieve().bodyToMono(Coins.class);
    }

The POJOs that are trying to bind it are:

@Data
public class Coins {

    @JsonProperty("success")
    private String success;

    @JsonProperty("playload")
    private List<Coin> playload;

and

@Data
public class Coin {

    @JsonProperty("book")
    private String book;

    @JsonProperty("minimum_amount")
    private String minimumAmount;

    @JsonProperty("maximum_amount")
    private String maximumAmount;

    @JsonProperty("minimum_price")
    private String minimumPrice;

    @JsonProperty("maximum_price")
    private String maximumPrice;

    @JsonProperty("minimum_value")
    private String minimumValue;

    @JsonProperty("maximum_value")
    private String maximumValue;

So far, it only maps like this

"success": true,
"payload": null
chuuck
  • 81
  • 1
  • 6

3 Answers3

1

You need to have no-args construct and change the word playload to payload :)

Javier Sainz
  • 301
  • 1
  • 2
  • 7
0

I don't think this is a WebFlux issue, but rather a Jackson + Lombok issue. What happens if you try to deserialize that payload with raw ObjectMapper?

I think Jackson requires an all args constructor annotated with @JsonCreator or ask Lombok to create a @NoArgConstructor for that class. In any case, rewriting your Coin class as a regular Java class should work.

Also, your Coins class has a typo since it's trying to get playload instead of payload.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
  • Thanks for the feedback. I tried both ways (different Lombok annotation and plain POJO but no difference). – chuuck Jan 15 '19 at 17:22
0

FIXED: Typo at property name playload instead of payload

chuuck
  • 81
  • 1
  • 6