Mapping fails with RestConnector for List/Array response

What product/components do you use and which version/fix level are you on?

Cumulocity IoT Microservice SDK / Cumulocity IoT Java Client 1015.334.0

What are you trying to achieve? Please describe it in detail.

I’m using the RestConnector to query an API of a Cumulocity microservice. This API returns a json response with an array of elements:

[
  {
    "id": "99474283"
  },
  {
    "id": "99473435"
  },
  {
    "id": "99475233"
  }
]

I tried different approaches to map this into Java POJOs but get an exception every time:

Configuration[] configurations = restConnector.get(path, MediaType.APPLICATION_JSON_TYPE, Configuration[].class);
Configuration[] configurations = restConnector.get(path, CumulocityMediaType.APPLICATION_JSON_TYPE, Configuration[].class);
List<Configuration> arrayList = response.readEntity(new GenericType<List<Configuration>>() {});
List<Configuration> configurationsList = restConnector.get(path, MediaType.APPLICATION_JSON_TYPE, List.class);

Those attempts all fail with error messages similar to:

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json, type=class [Lcom.adamos.oee.datamodel.Configuration;, genericType=class [LConfiguration;.
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json, type=interface java.util.List, genericType=interface java.util.List.
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=application/json, type=interface java.util.List, genericType=java.util.List<Configuration>.

Before using the RestConnector, we used the (now deprecated) RestTemplate and it works:
ResponseEntity<Configuration[]> configurations = restTemplate.getForEntity(uri, Configuration[].class);

For now I solved the problem by mapping the response individually:

String responseJson = restConnector.get(path, CumulocityMediaType.APPLICATION_JSON_TYPE, String.class);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Configuration[] configurations = mapper.readValue(responseJson, Configuration[].class);

Am I doing something wrong or does the RestConnector (not yet) support mapping arrays/lists?

Thanks a lot
Michael

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.