diff --git a/api/src/main/resources/custom_templates/ApiClient.mustache b/api/src/main/resources/custom_templates/ApiClient.mustache index a791986621c..adbb1555717 100644 --- a/api/src/main/resources/custom_templates/ApiClient.mustache +++ b/api/src/main/resources/custom_templates/ApiClient.mustache @@ -178,6 +178,7 @@ protected List servers = new ArrayList objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); + objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); {{#joda}} objectMapper.registerModule(new JodaModule()); {{/joda}} @@ -900,6 +901,16 @@ protected List servers = new ArrayList return null; } + // some responses of list type contain a root element that need to be stripped before passing to ObjectMapper + if (valueRawType.getTypeName().contains("java.util.List")) { + if (content.startsWith("{\"")) { + // remove leading {"blahblah": + content = content.substring(content.indexOf(":") + 1); + // remove trailing } + content = content.substring(0, content.length() - 1); + } + } + T value = objectMapper.readValue(content, valueType); return value instanceof List ? PagedList.constructPagedList(response, value) : value; } else if ("text/plain".equalsIgnoreCase(mimeType)) {