Skip to content

Commit 8dccb12

Browse files
authored
Merge pull request #727 from aws/marshaller-refactor
Refactoring for JSON marshalling/unmarshalling, support for JSON valu…
2 parents 4ff5bb5 + dc44552 commit 8dccb12

File tree

169 files changed

+5855
-4573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+5855
-4573
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/AddShapes.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ private MemberModel generateMemberModel(String c2jMemberName, Member c2jMemberDe
162162
.withVariable(new VariableModel(variableName, variableType, variableDeclarationType)
163163
.withDocumentation(c2jMemberDefinition.getDocumentation()))
164164
.withSetterModel(new VariableModel(variableName, variableType, variableDeclarationType))
165-
.withGetterModel(new ReturnTypeModel(variableType));
165+
.withGetterModel(new ReturnTypeModel(variableType))
166+
.withTimestampFormat(resolveTimestampFormat(c2jMemberDefinition, c2jShape))
167+
.withJsonValue(c2jMemberDefinition.getJsonValue());
166168
memberModel.setDocumentation(c2jMemberDefinition.getDocumentation());
167169
memberModel.setDeprecated(c2jMemberDefinition.isDeprecated());
168170
memberModel
@@ -205,6 +207,11 @@ private MemberModel generateMemberModel(String c2jMemberName, Member c2jMemberDe
205207
return memberModel;
206208
}
207209

210+
private String resolveTimestampFormat(Member c2jMemberDefinition, Shape c2jShape) {
211+
return c2jMemberDefinition.getTimestampFormat() != null ?
212+
c2jMemberDefinition.getTimestampFormat() : c2jShape.getTimestampFormat();
213+
}
214+
208215
private ParameterHttpMapping generateParameterHttpMapping(Shape parentShape,
209216
String memberName,
210217
Member member,

codegen/src/main/java/software/amazon/awssdk/codegen/IntermediateModelBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static software.amazon.awssdk.codegen.AddMetadata.constructMetadata;
1919
import static software.amazon.awssdk.codegen.RemoveUnusedShapes.removeUnusedShapes;
2020

21-
import java.io.IOException;
2221
import java.util.ArrayList;
2322
import java.util.Collections;
2423
import java.util.HashMap;
@@ -90,7 +89,7 @@ private List<IntermediateModelShapeProcessor> createShapeProcessors() {
9089
return processors;
9190
}
9291

93-
public IntermediateModel build() throws IOException {
92+
public IntermediateModel build() {
9493
// Note: This needs to come before any pre/post processing of the
9594
// models, as the transformer must have access to the original shapes,
9695
// before any customizations have been applied (which modifies them).
@@ -119,7 +118,7 @@ public IntermediateModel build() throws IOException {
119118

120119
IntermediateModel fullModel = new IntermediateModel(
121120
constructMetadata(service, codeGenConfig, customConfig), operations, shapes,
122-
customConfig, examples, authorizers, paginators.getPaginators());
121+
customConfig, examples, authorizers, paginators.getPaginators(), namingStrategy);
123122

124123
customization.postprocess(fullModel);
125124

@@ -135,7 +134,8 @@ public IntermediateModel build() throws IOException {
135134
fullModel.getCustomizationConfig(),
136135
fullModel.getExamples(),
137136
fullModel.getCustomAuthorizers(),
138-
fullModel.getPaginators());
137+
fullModel.getPaginators(),
138+
namingStrategy);
139139

140140
linkMembersToShapes(trimmedModel);
141141
linkOperationsToInputOutputShapes(trimmedModel);

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/MarshallerGeneratorTasks.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import software.amazon.awssdk.codegen.model.intermediate.Metadata;
3131
import software.amazon.awssdk.codegen.model.intermediate.ShapeModel;
3232
import software.amazon.awssdk.codegen.model.intermediate.ShapeType;
33-
import software.amazon.awssdk.codegen.poet.transform.JsonModelMarshallerSpec;
3433
import software.amazon.awssdk.codegen.poet.transform.MarshallerSpec;
3534
import software.amazon.awssdk.utils.ImmutableMap;
3635

@@ -48,7 +47,7 @@ public MarshallerGeneratorTasks(GeneratorTaskParams dependencies) {
4847
}
4948

5049
@Override
51-
protected List<GeneratorTask> createTasks() throws Exception {
50+
protected List<GeneratorTask> createTasks() {
5251
info("Emitting marshaller classes");
5352
return model.getShapes().entrySet().stream()
5453
.filter(e -> shouldGenerate(e.getValue()))
@@ -70,9 +69,8 @@ private boolean shouldGenerate(ShapeModel shapeModel) {
7069
private Stream<GeneratorTask> createTask(String javaShapeName, ShapeModel shapeModel) throws Exception {
7170
if (metadata.isJsonProtocol()) {
7271
return ShapeType.Request == shapeModel.getShapeType() ?
73-
Stream.of(createPoetGeneratorTask(new JsonModelMarshallerSpec(model, shapeModel, "ModelMarshaller")),
74-
createPoetGeneratorTask(new MarshallerSpec(model, shapeModel))) :
75-
Stream.of(createPoetGeneratorTask(new JsonModelMarshallerSpec(model, shapeModel, "Marshaller")));
72+
Stream.of(createPoetGeneratorTask(new MarshallerSpec(model, shapeModel))) :
73+
Stream.empty();
7674
}
7775

7876
return Stream.of(

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/UnmarshallerGeneratorTasks.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static software.amazon.awssdk.utils.FunctionalUtils.safeFunction;
1919

2020
import freemarker.template.Template;
21+
import java.util.Collections;
2122
import java.util.List;
2223
import java.util.Map;
2324
import java.util.stream.Collectors;
@@ -43,6 +44,9 @@ public UnmarshallerGeneratorTasks(GeneratorTaskParams dependencies) {
4344
@Override
4445
protected List<GeneratorTask> createTasks() throws Exception {
4546
info("Emitting unmarshaller classes");
47+
if (metadata.isJsonProtocol()) {
48+
return Collections.emptyList();
49+
}
4650
return model.getShapes().entrySet().stream()
4751
.filter(e -> shouldGenerate(e.getValue()))
4852
.map(safeFunction(e -> createTask(e.getKey(), e.getValue())))

codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.codegen.model.config.customization;
1717

1818
import java.util.ArrayList;
19+
import java.util.HashMap;
1920
import java.util.List;
2021
import java.util.Map;
2122
import software.amazon.awssdk.codegen.model.config.templates.CodeGenTemplatesConfig;
@@ -126,7 +127,7 @@ public class CustomizationConfig {
126127
private String sdkResponseBaseClassName;
127128
private String defaultExceptionUnmarshaller;
128129

129-
private Map<String, String> modelMarshallerDefaultValueSupplier;
130+
private Map<String, String> modelMarshallerDefaultValueSupplier = new HashMap<>();
130131

131132
private boolean useAutoConstructList = true;
132133

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/IntermediateModel.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import software.amazon.awssdk.codegen.internal.Utils;
3333
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
3434
import software.amazon.awssdk.codegen.model.service.PaginatorDefinition;
35+
import software.amazon.awssdk.codegen.naming.NamingStrategy;
3536
import software.amazon.awssdk.utils.IoUtils;
3637

3738
public final class IntermediateModel {
@@ -56,6 +57,9 @@ public final class IntermediateModel {
5657
@JsonIgnore
5758
private final Map<String, PaginatorDefinition> paginators;
5859

60+
@JsonIgnore
61+
private final NamingStrategy namingStrategy;
62+
5963
@JsonCreator
6064
public IntermediateModel(
6165
@JsonProperty("metadata") Metadata metadata,
@@ -64,7 +68,7 @@ public IntermediateModel(
6468
@JsonProperty("customizationConfig") CustomizationConfig customizationConfig,
6569
@JsonProperty("serviceExamples") ServiceExamples examples) {
6670

67-
this(metadata, operations, shapes, customizationConfig, examples, Collections.emptyMap(), Collections.emptyMap());
71+
this(metadata, operations, shapes, customizationConfig, examples, Collections.emptyMap(), Collections.emptyMap(), null);
6872
}
6973

7074
public IntermediateModel(
@@ -74,14 +78,16 @@ public IntermediateModel(
7478
CustomizationConfig customizationConfig,
7579
ServiceExamples examples,
7680
Map<String, AuthorizerModel> customAuthorizers,
77-
Map<String, PaginatorDefinition> paginators) {
81+
Map<String, PaginatorDefinition> paginators,
82+
NamingStrategy namingStrategy) {
7883
this.metadata = metadata;
7984
this.operations = operations;
8085
this.shapes = shapes;
8186
this.customizationConfig = customizationConfig;
8287
this.examples = examples;
8388
this.customAuthorizers = customAuthorizers;
8489
this.paginators = paginators;
90+
this.namingStrategy = namingStrategy;
8591
}
8692

8793
public Metadata getMetadata() {
@@ -116,6 +122,10 @@ public Map<String, PaginatorDefinition> getPaginators() {
116122
return paginators;
117123
}
118124

125+
public NamingStrategy getNamingStrategy() {
126+
return namingStrategy;
127+
}
128+
119129
/**
120130
* @return Exception unmarshaller implementation to use. Currently only needed by XML based
121131
* protocols.

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/MemberModel.java

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
import static software.amazon.awssdk.codegen.internal.DocumentationUtils.defaultSetter;
2323
import static software.amazon.awssdk.codegen.internal.DocumentationUtils.defaultSetterParam;
2424
import static software.amazon.awssdk.codegen.internal.DocumentationUtils.stripHtmlTags;
25-
import static software.amazon.awssdk.utils.StringUtils.upperCase;
2625

2726
import com.fasterxml.jackson.annotation.JsonIgnore;
2827
import java.util.List;
2928
import java.util.Map;
3029
import software.amazon.awssdk.codegen.internal.TypeUtils;
3130
import software.amazon.awssdk.core.SdkBytes;
31+
import software.amazon.awssdk.core.protocol.SdkField;
3232
import software.amazon.awssdk.core.runtime.transform.PathMarshaller;
3333
import software.amazon.awssdk.utils.StringUtils;
3434

@@ -74,6 +74,10 @@ public class MemberModel extends DocumentationModel {
7474

7575
private String beanStyleSetterName;
7676

77+
private boolean isJsonValue;
78+
79+
private String timestampFormat;
80+
7781
private boolean eventPayload;
7882

7983
private boolean eventHeader;
@@ -475,8 +479,9 @@ public boolean getIsBinary() {
475479
/**
476480
* @return Implementation of {@link PathMarshaller} to use if this member is bound the the URI.
477481
* @throws IllegalStateException If this member is not bound to the URI. Templates should first check
478-
* {@link ParameterHttpMapping#isUri()} first.
482+
* {@link ParameterHttpMapping#isUri()} first.
479483
*/
484+
// TODO remove when rest XML marshaller refactor is merged
480485
@JsonIgnore
481486
public String getPathMarshaller() {
482487
if (!http.isUri()) {
@@ -492,13 +497,30 @@ public String getPathMarshaller() {
492497
}
493498
}
494499

495-
/**
496-
* Used for JSON services. Name of the field containing the {@link software.amazon.awssdk.core.protocol.MarshallingInfo} for
497-
* this member.
498-
*/
499-
@JsonIgnore
500-
public String getMarshallerBindingFieldName() {
501-
return upperCase(this.name) + "_BINDING";
500+
public boolean isJsonValue() {
501+
return isJsonValue;
502+
}
503+
504+
public void setJsonValue(boolean jsonValue) {
505+
isJsonValue = jsonValue;
506+
}
507+
508+
public MemberModel withJsonValue(boolean jsonValue) {
509+
setJsonValue(jsonValue);
510+
return this;
511+
}
512+
513+
public String getTimestampFormat() {
514+
return timestampFormat;
515+
}
516+
517+
public void setTimestampFormat(String timestampFormat) {
518+
this.timestampFormat = timestampFormat;
519+
}
520+
521+
public MemberModel withTimestampFormat(String timestampFormat) {
522+
setTimestampFormat(timestampFormat);
523+
return this;
502524
}
503525

504526
@JsonIgnore
@@ -518,9 +540,7 @@ public boolean isSdkBytesType() {
518540
}
519541

520542
/**
521-
* Currently used only for JSON services.
522-
*
523-
* @return Marshalling type to use when creating a {@link software.amazon.awssdk.core.protocol.MarshallingInfo}. Must be a
543+
* @return Marshalling type to use when creating a {@link SdkField}. Must be a
524544
* field of {@link software.amazon.awssdk.core.protocol.MarshallingType}.
525545
*/
526546
public String getMarshallingType() {
@@ -529,29 +549,12 @@ public String getMarshallingType() {
529549
} else if (isMap()) {
530550
return "MAP";
531551
} else if (!isSimple()) {
532-
return "STRUCTURED";
552+
return "SDK_POJO";
533553
} else {
534554
return TypeUtils.getMarshallingType(variable.getSimpleType());
535555
}
536556
}
537557

538-
/**
539-
* Currently used only for JSON services.
540-
*
541-
* @return The target class a marshalling type is bound to.
542-
*/
543-
public String getMarshallingTargetClass() {
544-
if (isList()) {
545-
return "List";
546-
} else if (isMap()) {
547-
return "Map";
548-
} else if (!isSimple()) {
549-
return "StructuredPojo";
550-
} else {
551-
return variable.getVariableType();
552-
}
553-
}
554-
555558
@JsonIgnore
556559
public ShapeModel getShape() {
557560
return shape;

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/ParameterHttpMapping.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ public MarshallLocation getMarshallLocation() {
173173
switch (location) {
174174
default:
175175
return MarshallLocation.PAYLOAD;
176+
case STATUS_CODE:
177+
return MarshallLocation.STATUS_CODE;
176178
case HEADER:
177179
case HEADERS:
178180
return MarshallLocation.HEADER;

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/ShapeModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public MemberModel getExplicitEventPayloadMember() {
212212
}
213213

214214
return members.stream()
215-
.filter(m -> m.isEventPayload())
215+
.filter(MemberModel::isEventPayload)
216216
.findFirst()
217217
.orElse(null);
218218
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/Member.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public class Member {
4141

4242
private boolean deprecated;
4343

44+
@JsonProperty("jsonvalue")
45+
private boolean jsonValue;
46+
47+
private String timestampFormat;
48+
4449
@JsonProperty(value = "eventpayload")
4550
private boolean eventPayload;
4651

@@ -135,6 +140,22 @@ public void setDeprecated(boolean deprecated) {
135140
this.deprecated = deprecated;
136141
}
137142

143+
public boolean getJsonValue() {
144+
return jsonValue;
145+
}
146+
147+
public void setJsonValue(boolean jsonValue) {
148+
this.jsonValue = jsonValue;
149+
}
150+
151+
public String getTimestampFormat() {
152+
return timestampFormat;
153+
}
154+
155+
public void setTimestampFormat(String timestampFormat) {
156+
this.timestampFormat = timestampFormat;
157+
}
158+
138159
public boolean isEventPayload() {
139160
return eventPayload;
140161
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/Shape.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class Shape {
6767
@JsonProperty(value = "event")
6868
private boolean isEvent;
6969

70+
private String timestampFormat;
71+
7072
public boolean isFault() {
7173
return fault;
7274
}
@@ -238,4 +240,12 @@ public boolean isEvent() {
238240
public void setIsEvent(boolean event) {
239241
isEvent = event;
240242
}
243+
244+
public String getTimestampFormat() {
245+
return timestampFormat;
246+
}
247+
248+
public void setTimestampFormat(String timestampFormat) {
249+
this.timestampFormat = timestampFormat;
250+
}
241251
}

0 commit comments

Comments
 (0)