From 882a1fe31811ff413cf48c3f4a32759d6c645f17 Mon Sep 17 00:00:00 2001 From: Arvind Krishnakumar <61501885+arvindkrishnakumar-okta@users.noreply.github.com> Date: Fri, 4 Oct 2024 15:32:17 -0500 Subject: [PATCH] OKTA-803484: Fix deserialization issue with `BrandsApi::listBrandDomains()` response (#1566) OKTA-803484: Fix deserialization issue with BrandsApi::listBrandDomains() response --- .../resources/custom_templates/ApiClient.mustache | 11 +++++++++++ 1 file changed, 11 insertions(+) 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)) {