Skip to content

Commit 45e222a

Browse files
authored
Merge pull request #3884 from aws/hdavidh/revert-remove-fast-unmarshaller
Revert remove fast unmarshaller
2 parents 567f029 + 3608fbe commit 45e222a

File tree

380 files changed

+796
-350
lines changed

Some content is hidden

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

380 files changed

+796
-350
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import software.amazon.awssdk.identity.spi.IdentityProvider;
8282
import software.amazon.awssdk.identity.spi.IdentityProviders;
8383
import software.amazon.awssdk.identity.spi.TokenIdentity;
84+
import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption;
8485
import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption;
8586
import software.amazon.awssdk.utils.AttributeMap;
8687
import software.amazon.awssdk.utils.CollectionUtils;
@@ -507,6 +508,13 @@ private MethodSpec finalizeServiceConfigurationMethod() {
507508
.addCode(" .fipsEnabled(c.get($T.FIPS_ENDPOINT_ENABLED))", AwsClientOption.class)
508509
.addCode(" .build());");
509510

511+
if (model.getMetadata().isJsonProtocol()) {
512+
if (model.getCustomizationConfig().getEnableFastUnmarshaller()) {
513+
builder.addStatement("builder.option($1T.ENABLE_FAST_UNMARSHALLER, true)",
514+
SdkClientJsonProtocolAdvancedOption.class);
515+
}
516+
}
517+
510518
if (hasRequestAlgorithmMember(model) || hasResponseAlgorithms(model)) {
511519
builder.addStatement("$T clientConfig = config", SdkClientConfiguration.class);
512520

core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/BaseAwsJsonProtocolFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import software.amazon.awssdk.protocols.json.internal.unmarshall.JsonProtocolUnmarshaller;
5454
import software.amazon.awssdk.protocols.json.internal.unmarshall.JsonResponseHandler;
5555
import software.amazon.awssdk.protocols.json.internal.unmarshall.ProtocolUnmarshallDependencies;
56+
import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption;
5657

5758
@SdkProtectedApi
5859
public abstract class BaseAwsJsonProtocolFactory {
@@ -87,7 +88,16 @@ protected BaseAwsJsonProtocolFactory(Builder<?> builder) {
8788
this.customErrorCodeFieldName = builder.customErrorCodeFieldName;
8889
this.hasAwsQueryCompatible = builder.hasAwsQueryCompatible;
8990
this.clientConfiguration = builder.clientConfiguration;
91+
Boolean enableFastUnmarshalling = false;
92+
if (clientConfiguration != null) {
93+
enableFastUnmarshalling =
94+
clientConfiguration.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER);
95+
if (enableFastUnmarshalling == null) {
96+
enableFastUnmarshalling = false;
97+
}
98+
}
9099
this.protocolUnmarshaller = JsonProtocolUnmarshaller.builder()
100+
.enableFastUnmarshalling(enableFastUnmarshalling)
91101
.protocolUnmarshallDependencies(
92102
builder.protocolUnmarshallDependencies.get())
93103
.build();

core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/unmarshall/JsonProtocolUnmarshaller.java

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import software.amazon.awssdk.protocols.json.internal.MarshallerUtil;
4949
import software.amazon.awssdk.protocols.json.internal.unmarshall.document.DocumentUnmarshaller;
5050
import software.amazon.awssdk.protocols.jsoncore.JsonNode;
51+
import software.amazon.awssdk.protocols.jsoncore.JsonNodeParser;
5152
import software.amazon.awssdk.protocols.jsoncore.JsonValueNodeFactory;
5253
import software.amazon.awssdk.utils.Lazy;
5354
import software.amazon.awssdk.utils.builder.Buildable;
@@ -58,24 +59,42 @@
5859
*/
5960
@SdkInternalApi
6061
@ThreadSafe
61-
public final class JsonProtocolUnmarshaller {
62+
public class JsonProtocolUnmarshaller {
6263
private static final Lazy<DefaultProtocolUnmarshallDependencies> DEFAULT_DEPENDENCIES =
6364
new Lazy<>(JsonProtocolUnmarshaller::newProtocolUnmarshallDependencies);
6465

6566
private final JsonUnmarshallerRegistry registry;
6667
private final JsonUnmarshallingParser unmarshallingParser;
68+
private final JsonNodeParser parser;
6769

6870
private JsonProtocolUnmarshaller(Builder builder) {
6971
ProtocolUnmarshallDependencies dependencies = builder.protocolUnmarshallDependencies;
7072
this.registry = dependencies.jsonUnmarshallerRegistry();
71-
this.unmarshallingParser = JsonUnmarshallingParser.builder()
72-
.jsonValueNodeFactory(dependencies.nodeValueFactory())
73-
.jsonFactory(dependencies.jsonFactory())
74-
.unmarshallerRegistry(dependencies.jsonUnmarshallerRegistry())
75-
.defaultTimestampFormat(dependencies.timestampFormats()
76-
.get(MarshallLocation.PAYLOAD))
73+
if (builder.enableFastUnmarshalling) {
74+
this.unmarshallingParser = JsonUnmarshallingParser.builder()
75+
.jsonValueNodeFactory(dependencies.nodeValueFactory())
76+
.jsonFactory(dependencies.jsonFactory())
77+
.unmarshallerRegistry(dependencies.jsonUnmarshallerRegistry())
78+
.defaultTimestampFormat(dependencies.timestampFormats()
79+
.get(MarshallLocation.PAYLOAD))
80+
81+
.build();
82+
this.parser = null;
83+
} else {
84+
this.unmarshallingParser = null;
85+
this.parser = createParser(builder, dependencies);
86+
}
87+
}
7788

78-
.build();
89+
private JsonNodeParser createParser(Builder builder, ProtocolUnmarshallDependencies dependencies) {
90+
if (builder.parser != null) {
91+
return builder.parser;
92+
}
93+
return JsonNodeParser
94+
.builder()
95+
.jsonFactory(dependencies.jsonFactory())
96+
.jsonValueNodeFactory(dependencies.nodeValueFactory())
97+
.build();
7998
}
8099

81100
public static DefaultProtocolUnmarshallDependencies defaultProtocolUnmarshallDependencies() {
@@ -220,6 +239,15 @@ public T unmarshall(JsonUnmarshallerContext context,
220239

221240
public <TypeT extends SdkPojo> TypeT unmarshall(SdkPojo sdkPojo,
222241
SdkHttpFullResponse response) throws IOException {
242+
if (this.unmarshallingParser != null) {
243+
return fastUnmarshall(sdkPojo, response);
244+
}
245+
JsonNode jsonNode = hasJsonPayload(sdkPojo, response) ? parser.parse(response.content().get()) : null;
246+
return unmarshall(sdkPojo, response, jsonNode);
247+
}
248+
249+
private <TypeT extends SdkPojo> TypeT fastUnmarshall(SdkPojo sdkPojo,
250+
SdkHttpFullResponse response) throws IOException {
223251
if (!hasJsonPayload(sdkPojo, response)) {
224252
return unmarshallResponse(sdkPojo, response);
225253
}
@@ -425,11 +453,23 @@ public static JsonUnmarshallerRegistry timestampFormatRegistryFactory(
425453
* Builder for {@link JsonProtocolUnmarshaller}.
426454
*/
427455
public static final class Builder {
456+
457+
private JsonNodeParser parser;
428458
private ProtocolUnmarshallDependencies protocolUnmarshallDependencies;
459+
private boolean enableFastUnmarshalling = false;
429460

430461
private Builder() {
431462
}
432463

464+
/**
465+
* @param parser JSON parser to use.
466+
* @return This builder for method chaining.
467+
*/
468+
public Builder parser(JsonNodeParser parser) {
469+
this.parser = parser;
470+
return this;
471+
}
472+
433473
/**
434474
* @param formats The default timestamp formats for each location in the HTTP response.
435475
* @return This builder for method chaining.
@@ -451,6 +491,15 @@ public Builder protocolUnmarshallDependencies(
451491
return this;
452492
}
453493

494+
/**
495+
* @param enableFastUnmarshalling Whether to enable the fast unmarshalling codepath. Default to {@code false}.
496+
* @return This builder for method chaining.
497+
*/
498+
public Builder enableFastUnmarshalling(boolean enableFastUnmarshalling) {
499+
this.enableFastUnmarshalling = enableFastUnmarshalling;
500+
return this;
501+
}
502+
454503
/**
455504
* @return New instance of {@link JsonProtocolUnmarshaller}.
456505
*/
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/acm/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"verifiedSimpleMethods": [
33
"listCertificates"
44
],
5-
"enableGenerateCompiledEndpointRules": true
5+
"enableGenerateCompiledEndpointRules": true,
6+
"enableFastUnmarshaller": true
67
}

services/acmpca/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"verifiedSimpleMethods": [
33
"listCertificateAuthorities"
44
],
5-
"enableGenerateCompiledEndpointRules": true
5+
"enableGenerateCompiledEndpointRules": true,
6+
"enableFastUnmarshaller": true
67
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/amplify/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"verifiedSimpleMethods": [
33
"listApps"
44
],
5-
"enableGenerateCompiledEndpointRules": true
5+
"enableGenerateCompiledEndpointRules": true,
6+
"enableFastUnmarshaller": true
67
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/apigateway/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
"interceptors": [
2525
"software.amazon.awssdk.services.apigateway.internal.AcceptJsonInterceptor"
2626
],
27-
"enableGenerateCompiledEndpointRules": true
27+
"enableGenerateCompiledEndpointRules": true,
28+
"enableFastUnmarshaller": true
2829
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/apigatewayv2/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"getApis",
44
"getDomainNames"
55
],
6-
"enableGenerateCompiledEndpointRules": true
6+
"enableGenerateCompiledEndpointRules": true,
7+
"enableFastUnmarshaller": true
78
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/applicationdiscovery/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
"DescribeExportConfigurations",
1818
"ExportConfigurations"
1919
],
20-
"enableGenerateCompiledEndpointRules": true
20+
"enableGenerateCompiledEndpointRules": true,
21+
"enableFastUnmarshaller": true
2122
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
{
2+
"enableFastUnmarshaller": true
23
}

services/appmesh/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"verifiedSimpleMethods": [
33
"listMeshes"
44
],
5-
"enableGenerateCompiledEndpointRules": true
5+
"enableGenerateCompiledEndpointRules": true,
6+
"enableFastUnmarshaller": true
67
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/appstream/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"describeImages",
1111
"describeStacks"
1212
],
13-
"enableGenerateCompiledEndpointRules": true
13+
"enableGenerateCompiledEndpointRules": true,
14+
"enableFastUnmarshaller": true
1415
}

services/appsync/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"verifiedSimpleMethods": [
33
"listGraphqlApis"
44
],
5-
"enableGenerateCompiledEndpointRules": true
5+
"enableGenerateCompiledEndpointRules": true,
6+
"enableFastUnmarshaller": true
67
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
{
2+
"enableFastUnmarshaller": true
23
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/athena/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"listNamedQueries",
44
"listQueryExecutions"
55
],
6-
"enableGenerateCompiledEndpointRules": true
6+
"enableGenerateCompiledEndpointRules": true,
7+
"enableFastUnmarshaller": true
78
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/autoscalingplans/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"verifiedSimpleMethods": [
33
"describeScalingPlans"
44
],
5-
"enableGenerateCompiledEndpointRules": true
5+
"enableGenerateCompiledEndpointRules": true,
6+
"enableFastUnmarshaller": true
67
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}

services/backup/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"listProtectedResources",
1111
"listRestoreJobs"
1212
],
13-
"enableGenerateCompiledEndpointRules": true
13+
"enableGenerateCompiledEndpointRules": true,
14+
"enableFastUnmarshaller": true
1415
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"enableGenerateCompiledEndpointRules": true
2+
"enableGenerateCompiledEndpointRules": true,
3+
"enableFastUnmarshaller": true
34
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
{
2+
"enableFastUnmarshaller": true
23
}

services/batch/src/main/resources/codegen-resources/customization.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"excludedSimpleMethods": [
88
"listJobs"
99
],
10-
"enableGenerateCompiledEndpointRules": true
10+
"enableGenerateCompiledEndpointRules": true,
11+
"enableFastUnmarshaller": true
1112
}

0 commit comments

Comments
 (0)