Apache Camel: Cannot deserialize instance of out of START_ARRAY token

Viewed 623

I go over http to the rest service, which returns this json:

[
  {
    "name":"D",
    "surname":"D"
  },
  {
    "name":"T",
    "surname":"T"
  }
]

In order to change it to an object when called, I created this structure:

@Data
public class User {
    String name;
    String surname;
}

I tried to take it like this:

public static void addDirectRestRoute(RouteBuilder routeBuilder, String directEndpointName, String url, String a) {
    routeBuilder.from("direct://" + directEndpointName)
        .setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
        .setHeader(Exchange.HTTP_METHOD).constant(HttpMethod.GET)
        //.setHeader(Exchange.HTTP_QUERY, simple("?id=1"))
        .to(url)
        .unmarshal().json(JsonLibrary.Jackson, User.class);
        //.unmarshal(new JacksonDataFormat(User.class));
}

Get an error. I tried this:

@Data
public class User {
    List<U> u;

    @Data
    public class U {
        String name;
        String surname;
    }
}

I still get an error. Here's the error:

[ERROR] r.s.e.g.i.r.s.ShopImportRoute - Cannot deserialize instance of `ru.sportmaster.esm.geogate.integration.domain.dto.User` out of START_ARRAY token
 at [Source: (org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream); line: 1, column: 1]
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `ru.sportmaster.esm.geogate.integration.domain.dto.User` out of START_ARRAY token
 at [Source: (org.apache.camel.converter.stream.CachedOutputStream$WrappedInputStream); line: 1, column: 1]
    at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
    at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1343)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1139)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1093)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromArray(BeanDeserializerBase.java:1461)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:185)

What is wrong with my data structure?

0 Answers
Related