From 3b7c762dc5f8f0faa5984221f4bfb09a20dc2070 Mon Sep 17 00:00:00 2001 From: Flanker32 Date: Wed, 30 Oct 2024 15:39:43 +0800 Subject: [PATCH] Fix serialize case issue for flex app functionAppConfig --- .../lib/appservice/function/FunctionAppBase.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionAppBase.java b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionAppBase.java index 5a93c0a9d..e0f35e7fa 100644 --- a/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionAppBase.java +++ b/azure-toolkit-libs/azure-toolkit-appservice-lib/src/main/java/com/microsoft/azure/toolkit/lib/appservice/function/FunctionAppBase.java @@ -11,6 +11,7 @@ import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpRequest; import com.azure.core.http.HttpResponse; import com.azure.core.management.serializer.SerializerFactory; +import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; import com.azure.core.util.serializer.SerializerEncoding; import com.azure.resourcemanager.appservice.AppServiceManager; @@ -19,6 +20,8 @@ import com.azure.resourcemanager.appservice.models.JavaVersion; import com.azure.resourcemanager.appservice.models.PlatformArchitecture; import com.azure.resourcemanager.appservice.models.WebAppBase; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.microsoft.azure.toolkit.lib.appservice.AppServiceAppBase; import com.microsoft.azure.toolkit.lib.appservice.deploy.FTPFunctionDeployHandler; @@ -233,7 +236,7 @@ public abstract class FunctionAppBase, P exte .setHeader(HttpHeaderName.CONTENT_TYPE, "application/json"); try (final HttpResponse block = httpPipeline.send(request).block()) { final String content = Optional.ofNullable(block).map(HttpResponse::getBodyAsString).map(Mono::block).orElse(StringUtils.EMPTY); - final SerializerAdapter adapter = SerializerFactory.createDefaultManagementSerializerAdapter(); + final SerializerAdapter adapter = new JacksonAdapter(this::configureSerialization); final ObjectNode functionNode = adapter.deserialize(content, ObjectNode.class, SerializerEncoding.JSON); final JsonNode configNode = Optional.ofNullable(functionNode.get("properties")).map(propertiesNode -> propertiesNode.get("functionAppConfig")).orElse(null); return Objects.isNull(configNode) ? null : adapter.deserialize(configNode.toPrettyString(), FunctionAppConfig.class, SerializerEncoding.JSON); @@ -242,6 +245,13 @@ public abstract class FunctionAppBase, P exte } } + // workaround to fix case issue from function service + // todo: migrate to sdk instead of raw request + private void configureSerialization(ObjectMapper outerMapper, ObjectMapper innerMapper) { + outerMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true); + innerMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true); + } + public String getRawRequestEndpoint(@Nonnull com.azure.resourcemanager.appservice.models.WebAppBase functionApp) { final AppServiceManager manager = functionApp.manager(); final WebSiteManagementClient client = manager.serviceClient();