Skip to content

Remove fast unmarshaller dialup code #6050

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 8 commits into from
Apr 24, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import software.amazon.awssdk.identity.spi.IdentityProvider;
import software.amazon.awssdk.identity.spi.IdentityProviders;
import software.amazon.awssdk.identity.spi.TokenIdentity;
import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption;
import software.amazon.awssdk.regions.ServiceMetadataAdvancedOption;
import software.amazon.awssdk.utils.AttributeMap;
import software.amazon.awssdk.utils.CollectionUtils;
Expand Down Expand Up @@ -508,13 +507,6 @@ private MethodSpec finalizeServiceConfigurationMethod() {
.addCode(" .fipsEnabled(c.get($T.FIPS_ENDPOINT_ENABLED))", AwsClientOption.class)
.addCode(" .build());");

if (model.getMetadata().isJsonProtocol()) {
if (model.getCustomizationConfig().getEnableFastUnmarshaller()) {
builder.addStatement("builder.option($1T.ENABLE_FAST_UNMARSHALLER, true)",
SdkClientJsonProtocolAdvancedOption.class);
}
}

if (hasRequestAlgorithmMember(model) || hasResponseAlgorithms(model)) {
builder.addStatement("$T clientConfig = config", SdkClientConfiguration.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import software.amazon.awssdk.protocols.json.internal.unmarshall.JsonProtocolUnmarshaller;
import software.amazon.awssdk.protocols.json.internal.unmarshall.JsonResponseHandler;
import software.amazon.awssdk.protocols.json.internal.unmarshall.ProtocolUnmarshallDependencies;
import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption;

@SdkProtectedApi
public abstract class BaseAwsJsonProtocolFactory {
Expand Down Expand Up @@ -88,16 +87,7 @@ protected BaseAwsJsonProtocolFactory(Builder<?> builder) {
this.customErrorCodeFieldName = builder.customErrorCodeFieldName;
this.hasAwsQueryCompatible = builder.hasAwsQueryCompatible;
this.clientConfiguration = builder.clientConfiguration;
Boolean enableFastUnmarshalling = false;
if (clientConfiguration != null) {
enableFastUnmarshalling =
clientConfiguration.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER);
if (enableFastUnmarshalling == null) {
enableFastUnmarshalling = false;
}
}
this.protocolUnmarshaller = JsonProtocolUnmarshaller.builder()
.enableFastUnmarshalling(enableFastUnmarshalling)
.protocolUnmarshallDependencies(
builder.protocolUnmarshallDependencies.get())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import software.amazon.awssdk.protocols.json.internal.MarshallerUtil;
import software.amazon.awssdk.protocols.json.internal.unmarshall.document.DocumentUnmarshaller;
import software.amazon.awssdk.protocols.jsoncore.JsonNode;
import software.amazon.awssdk.protocols.jsoncore.JsonNodeParser;
import software.amazon.awssdk.protocols.jsoncore.JsonValueNodeFactory;
import software.amazon.awssdk.utils.Lazy;
import software.amazon.awssdk.utils.builder.Buildable;
Expand All @@ -59,42 +58,24 @@
*/
@SdkInternalApi
@ThreadSafe
public class JsonProtocolUnmarshaller {
public final class JsonProtocolUnmarshaller {
private static final Lazy<DefaultProtocolUnmarshallDependencies> DEFAULT_DEPENDENCIES =
new Lazy<>(JsonProtocolUnmarshaller::newProtocolUnmarshallDependencies);

private final JsonUnmarshallerRegistry registry;
private final JsonUnmarshallingParser unmarshallingParser;
private final JsonNodeParser parser;

private JsonProtocolUnmarshaller(Builder builder) {
ProtocolUnmarshallDependencies dependencies = builder.protocolUnmarshallDependencies;
this.registry = dependencies.jsonUnmarshallerRegistry();
if (builder.enableFastUnmarshalling) {
this.unmarshallingParser = JsonUnmarshallingParser.builder()
.jsonValueNodeFactory(dependencies.nodeValueFactory())
.jsonFactory(dependencies.jsonFactory())
.unmarshallerRegistry(dependencies.jsonUnmarshallerRegistry())
.defaultTimestampFormat(dependencies.timestampFormats()
.get(MarshallLocation.PAYLOAD))

.build();
this.parser = null;
} else {
this.unmarshallingParser = null;
this.parser = createParser(builder, dependencies);
}
}
this.unmarshallingParser = JsonUnmarshallingParser.builder()
.jsonValueNodeFactory(dependencies.nodeValueFactory())
.jsonFactory(dependencies.jsonFactory())
.unmarshallerRegistry(dependencies.jsonUnmarshallerRegistry())
.defaultTimestampFormat(dependencies.timestampFormats()
.get(MarshallLocation.PAYLOAD))

private JsonNodeParser createParser(Builder builder, ProtocolUnmarshallDependencies dependencies) {
if (builder.parser != null) {
return builder.parser;
}
return JsonNodeParser
.builder()
.jsonFactory(dependencies.jsonFactory())
.jsonValueNodeFactory(dependencies.nodeValueFactory())
.build();
.build();
}

public static DefaultProtocolUnmarshallDependencies defaultProtocolUnmarshallDependencies() {
Expand Down Expand Up @@ -239,15 +220,6 @@ public T unmarshall(JsonUnmarshallerContext context,

public <TypeT extends SdkPojo> TypeT unmarshall(SdkPojo sdkPojo,
SdkHttpFullResponse response) throws IOException {
if (this.unmarshallingParser != null) {
return fastUnmarshall(sdkPojo, response);
}
JsonNode jsonNode = hasJsonPayload(sdkPojo, response) ? parser.parse(response.content().get()) : null;
return unmarshall(sdkPojo, response, jsonNode);
}

private <TypeT extends SdkPojo> TypeT fastUnmarshall(SdkPojo sdkPojo,
SdkHttpFullResponse response) throws IOException {
if (!hasJsonPayload(sdkPojo, response)) {
return unmarshallResponse(sdkPojo, response);
}
Expand Down Expand Up @@ -453,23 +425,11 @@ public static JsonUnmarshallerRegistry timestampFormatRegistryFactory(
* Builder for {@link JsonProtocolUnmarshaller}.
*/
public static final class Builder {

private JsonNodeParser parser;
private ProtocolUnmarshallDependencies protocolUnmarshallDependencies;
private boolean enableFastUnmarshalling = false;

private Builder() {
}

/**
* @param parser JSON parser to use.
* @return This builder for method chaining.
*/
public Builder parser(JsonNodeParser parser) {
this.parser = parser;
return this;
}

/**
* @param formats The default timestamp formats for each location in the HTTP response.
* @return This builder for method chaining.
Expand All @@ -491,15 +451,6 @@ public Builder protocolUnmarshallDependencies(
return this;
}

/**
* @param enableFastUnmarshalling Whether to enable the fast unmarshalling codepath. Default to {@code false}.
* @return This builder for method chaining.
*/
public Builder enableFastUnmarshalling(boolean enableFastUnmarshalling) {
this.enableFastUnmarshalling = enableFastUnmarshalling;
return this;
}

/**
* @return New instance of {@link JsonProtocolUnmarshaller}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.annotations.SdkProtectedApi;
import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata;
import software.amazon.awssdk.awscore.internal.AwsServiceProtocol;
import software.amazon.awssdk.core.internal.interceptor.trait.RequestCompression;
import software.amazon.awssdk.core.internal.util.MetricUtils;
import software.amazon.awssdk.core.internal.waiters.WaiterAttribute;
import software.amazon.awssdk.http.auth.aws.internal.signer.util.ChecksumUtil;
import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption;
import software.amazon.awssdk.utils.internal.EnumUtils;
import software.amazon.awssdk.utils.internal.SystemSettingUtils;

Expand All @@ -57,7 +55,7 @@ public class InternalApiBoundaryTest {
private static final Set<Class<?>> ALLOWED_INTERNAL_API_ACROSS_MODULE_SUPPRESSION = new HashSet<>(
Arrays.asList(WaiterAttribute.class, RequestCompression.class, RequestCompression.Builder.class, EnumUtils.class,
AwsServiceProtocol.class, AwsProtocolMetadata.class, MetricUtils.class, SystemSettingUtils.class,
ChecksumUtil.class, SdkClientJsonProtocolAdvancedOption.class));
ChecksumUtil.class));

@Test
void internalApi_shouldNotUsedAcrossModule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public SdkPojo unmarshall(AwsJsonProtocol protocol, SdkPojo pojo, byte[] bytes)
JsonProtocolUnmarshaller unmarshaller =
JsonProtocolUnmarshaller
.builder()
.enableFastUnmarshalling(true)
.protocolUnmarshallDependencies(behavior.protocolUnmarshallDependencies())
.build();
SdkHttpFullResponse response = SdkHttpFullResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
import software.amazon.awssdk.protocols.json.internal.unmarshall.SdkClientJsonProtocolAdvancedOption;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.BackupInUseException;
import software.amazon.awssdk.services.dynamodb.model.BackupNotFoundException;
Expand Down Expand Up @@ -80,7 +79,6 @@ public class V2DynamoDbAttributeValue {
.clientConfiguration(SdkClientConfiguration
.builder()
.option(SdkClientOption.ENDPOINT, URI.create("https://localhost"))
.option(SdkClientJsonProtocolAdvancedOption.ENABLE_FAST_UNMARSHALLER, true)
.build())
.defaultServiceExceptionSupplier(DynamoDbException::builder)
.protocol(AwsJsonProtocol.AWS_JSON)
Expand Down
Loading