Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AmazonDynamoDB-474adb8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Amazon DynamoDB",
"contributor": "",
"description": "Add a `setNull(Boolean)` setter for the serializable builder class returned by `AttributeValue.serializableBuilderClass()`. This allows successfully converting from a JSON blob such as `{\"NULL\": true}`."
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ private MemberModel generateMemberModel(String c2jMemberName, Member c2jMemberDe
memberModel.setRequired(isRequiredMember(c2jMemberName, parentShape));
memberModel.setSynthetic(shape.isSynthetic());

if (c2jMemberDefinition.getAlternateBeanPropertyName() != null) {
String alternatePropertyName = c2jMemberDefinition.getAlternateBeanPropertyName();

String setter = String.format("set%s", alternatePropertyName);

memberModel.setAdditionalBeanStyleSetterName(setter);
}


// Pass the xmlNameSpace from the member reference
if (c2jMemberDefinition.getXmlNamespace() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ private void doModifyShapeMembers(ServiceModel serviceModel, Shape shape, String
member.setDeprecatedMessage(modifyModel.getDeprecatedMessage());
}
}

if (modifyModel.getAlternateBeanPropertyName() != null) {
shape.getMembers().get(memberToModify).setAlternateBeanPropertyName(modifyModel.getAlternateBeanPropertyName());
}

// Currently only supports emitPropertyName which is to rename the member
if (modifyModel.getEmitPropertyName() != null) {
Member member = shape.getMembers().remove(memberToModify);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public class ModifyModelShapeModifier {
*/
private String emitEnumValue;

/**
* An additional, alternate name for this member that should additionally be used when generating bean style
* setters/getters for the enclosing shape.
*/
private String alternateBeanPropertyName;

/**
* Emit as a different primitive type. Used by AWS Budget Service to change string
* to BigDecimal (see API-433).
Expand Down Expand Up @@ -143,4 +149,12 @@ public void setIgnoreDataTypeConversionFailures(boolean ignoreDataTypeConversion
public boolean isIgnoreDataTypeConversionFailures() {
return ignoreDataTypeConversionFailures;
}

public String getAlternateBeanPropertyName() {
return alternateBeanPropertyName;
}

public void setAlternateBeanPropertyName(String alternateBeanPropertyName) {
this.alternateBeanPropertyName = alternateBeanPropertyName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public class MemberModel extends DocumentationModel {

private String beanStyleSetterName;

private String additionalBeanStyleSetterName;

private String unionEnumTypeName;

private boolean isJsonValue;
Expand Down Expand Up @@ -787,6 +789,19 @@ public boolean ignoreDataTypeConversionFailures() {
return ignoreDataTypeConversionFailures;
}

public String getAdditionalBeanStyleSetterName() {
return additionalBeanStyleSetterName;
}

public void setAdditionalBeanStyleSetterName(String additionalBeanStyleSetterName) {
this.additionalBeanStyleSetterName = additionalBeanStyleSetterName;
}

public MemberModel withAdditionalBeanStyleSetterName(String additionalBeanStyleSetterName) {
setAdditionalBeanStyleSetterName(additionalBeanStyleSetterName);
return this;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
Expand Down Expand Up @@ -834,6 +849,7 @@ public boolean equals(Object o) {
&& Objects.equals(fluentDeprecatedGetterMethodName, that.fluentDeprecatedGetterMethodName)
&& Objects.equals(fluentDeprecatedSetterMethodName, that.fluentDeprecatedSetterMethodName)
&& Objects.equals(deprecatedBeanStyleSetterMethodName, that.deprecatedBeanStyleSetterMethodName)
&& Objects.equals(additionalBeanStyleSetterName, that.additionalBeanStyleSetterName)
&& Objects.equals(contextParam, that.contextParam);
}

Expand Down Expand Up @@ -878,6 +894,8 @@ public int hashCode() {
result = 31 * result + Objects.hashCode(deprecatedBeanStyleSetterMethodName);
result = 31 * result + Objects.hashCode(contextParam);
result = 31 * result + Boolean.hashCode(ignoreDataTypeConversionFailures);
result = 31 * result + Objects.hashCode(additionalBeanStyleSetterName);

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public class Member {

private String deprecatedName;

/**
* An additional, alternate name for this member that should additionally be used when generating bean style
* setters/getters for the enclosing shape.
*/
private String alternateBeanPropertyName;

private ContextParam contextParam;

public String getShape() {
Expand Down Expand Up @@ -236,4 +242,12 @@ public ContextParam getContextParam() {
public void setContextParam(ContextParam contextParam) {
this.contextParam = contextParam;
}

public String getAlternateBeanPropertyName() {
return alternateBeanPropertyName;
}

public void setAlternateBeanPropertyName(String alternateBeanPropertyName) {
this.alternateBeanPropertyName = alternateBeanPropertyName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ public List<MethodSpec> beanStyle() {
.build());
}

String additionalSetter = memberModel().getAdditionalBeanStyleSetterName();
if (StringUtils.isNotBlank(additionalSetter)) {
MethodSpec.Builder methodBuilder = beanStyleSetterBuilder();
methodBuilder.setName(additionalSetter);
methods.add(methodBuilder.addCode(beanCopySetterBody())
.build());
}

return methods;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"modify": [
{
"NULL": {
"emitPropertyName": "NUL"
"emitPropertyName": "NUL",
"alternateBeanPropertyName": "Null"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"modify": [
{
"NULL": {
"emitPropertyName": "NUL"
"emitPropertyName": "NUL",
"alternateBeanPropertyName": "Null"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.services.dynamodb;

import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

public class AttributeValueTest {
private static ObjectMapper mapper;

@BeforeAll
public static void setup() {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
}

@Test
void serializableBuilderClass_jsonIsNullAttributeValue_deserializesCorrectly() throws JsonProcessingException {
String nullAttributeValueJson = "{\"NULL\":true}";

AttributeValue.Builder builder = mapper.readValue(nullAttributeValueJson, AttributeValue.serializableBuilderClass());
AttributeValue attr = builder.build();

assertThat(attr.nul()).isTrue();
}
}
Loading