From dddb38ed7801d1fabd0bef7f74951b18cd848a62 Mon Sep 17 00:00:00 2001 From: kai lin Date: Mon, 23 Mar 2026 15:45:12 -0400 Subject: [PATCH 1/2] Fix codegen for sparse collection JSON serialization --- .../velocity/cpp/json/ModelInternalMapOrListJsonize.vm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/ModelInternalMapOrListJsonize.vm b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/ModelInternalMapOrListJsonize.vm index 6b102baaae5..84661624cc9 100644 --- a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/ModelInternalMapOrListJsonize.vm +++ b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/ModelInternalMapOrListJsonize.vm @@ -25,6 +25,9 @@ #if($template.currentShape.sparse) #set($key = "${template.lowerCaseVarName}Item.first") #set($value = "*${template.lowerCaseVarName}Item.second${CppViewHelper.computeJsonizeString($template.currentShape.mapValue.shape)}") +#if($template.currentShape.mapValue.shape.isStructure() || $template.currentShape.mapValue.shape.isTimeStamp() || $template.currentShape.mapValue.shape.isDocument()) +#set($value = "${template.lowerCaseVarName}Item.second${CppViewHelper.computeJsonizeString($template.currentShape.mapValue.shape, true)}") +#end #if($template.currentShape.mapValue.shape.isBlob()) #set($value = "HashingUtils::Base64Encode(*${template.lowerCaseVarName}Item.second${CppViewHelper.computeJsonizeString($template.currentShape.mapValue.shape)})") #end @@ -86,7 +89,6 @@ #if($template.currentShape.sparse) ${template.currentSpaces} if(!${template.containerVar}[${template.lowerCaseVarName}Index].has_value()) ${template.currentSpaces} { - ${template.currentSpaces} ${template.lowerCaseVarName}JsonList[${template.lowerCaseVarName}Index].AsNull(); ${template.currentSpaces} continue; ${template.currentSpaces} } #end @@ -107,7 +109,11 @@ #end #else #if($template.currentShape.sparse) +#if($template.currentShape.listMember.shape.isStructure() || $template.currentShape.listMember.shape.isTimeStamp() || $template.currentShape.listMember.shape.isDocument()) + ${template.currentSpaces} ${template.lowerCaseVarName}JsonList[${template.lowerCaseVarName}Index].As${CppViewHelper.computeJsonCppType($template.currentShape.listMember.shape)}(${template.containerVar}[${template.lowerCaseVarName}Index]${CppViewHelper.computeJsonizeString($template.currentShape.listMember.shape, true)}); +#else ${template.currentSpaces} ${template.lowerCaseVarName}JsonList[${template.lowerCaseVarName}Index].As${CppViewHelper.computeJsonCppType($template.currentShape.listMember.shape)}(*${template.containerVar}[${template.lowerCaseVarName}Index]${CppViewHelper.computeJsonizeString($template.currentShape.listMember.shape)}); +#end #else ${template.currentSpaces} ${template.lowerCaseVarName}JsonList[${template.lowerCaseVarName}Index].As${CppViewHelper.computeJsonCppType($template.currentShape.listMember.shape)}(${template.containerVar}[${template.lowerCaseVarName}Index]${CppViewHelper.computeJsonizeString($template.currentShape.listMember.shape)}); #end From 9ce6e6e9bd7b01c8ba115b45cd69562c764294ce Mon Sep 17 00:00:00 2001 From: kai lin Date: Mon, 23 Mar 2026 17:15:19 -0400 Subject: [PATCH 2/2] Fix codegen for sparse collection JSON serialization --- .../include/aws/core/utils/json/JsonSerializer.h | 5 +++++ src/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp | 7 +++++++ .../velocity/cpp/json/ModelInternalMapOrListJsonize.vm | 1 + 3 files changed, 13 insertions(+) diff --git a/src/aws-cpp-sdk-core/include/aws/core/utils/json/JsonSerializer.h b/src/aws-cpp-sdk-core/include/aws/core/utils/json/JsonSerializer.h index ae98f6c18ff..fabbe7aaf33 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/utils/json/JsonSerializer.h +++ b/src/aws-cpp-sdk-core/include/aws/core/utils/json/JsonSerializer.h @@ -100,6 +100,11 @@ namespace Aws JsonValue& WithNull(const Aws::String& key); JsonValue& WithNull(const char* key); + /** + * Converts the current JSON node to null. + */ + JsonValue& AsNull(); + /** * Converts the current JSON node to a string. */ diff --git a/src/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp b/src/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp index bbf44e5b57d..25edf4363e9 100644 --- a/src/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp +++ b/src/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp @@ -170,6 +170,13 @@ JsonValue& JsonValue::WithNull(const Aws::String& key) return WithNull(key.c_str()); } +JsonValue& JsonValue::AsNull() +{ + Destroy(); + m_value = cJSON_AS4CPP_CreateNull(); + return *this; +} + JsonValue& JsonValue::AsString(const Aws::String& value) { Destroy(); diff --git a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/ModelInternalMapOrListJsonize.vm b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/ModelInternalMapOrListJsonize.vm index 84661624cc9..1a03e9e5ace 100644 --- a/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/ModelInternalMapOrListJsonize.vm +++ b/tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/ModelInternalMapOrListJsonize.vm @@ -89,6 +89,7 @@ #if($template.currentShape.sparse) ${template.currentSpaces} if(!${template.containerVar}[${template.lowerCaseVarName}Index].has_value()) ${template.currentSpaces} { + ${template.currentSpaces} ${template.lowerCaseVarName}JsonList[${template.lowerCaseVarName}Index].AsNull(); ${template.currentSpaces} continue; ${template.currentSpaces} } #end