Open
Description
Describe the issue
I am trying to migrate some code from the SDK v1 to the SDK v2 and one of the last hurdle is the following piece of code:
import com.amazonaws.util.json.Jackson;
...
private static Optional<AwsConfig> deserializeConfig(final Map<String, Object> config) {
if (config == null) {
return Optional.empty();
}
for (final Class<?> clazz : new Class<?>[] {AwsKeyPairConfig.class, AwsKmsConfig.class}) {
try {
return Optional.of((AwsConfig) Jackson.getObjectMapper().convertValue(config, clazz));
} catch (final IllegalArgumentException exception) {
LOGGER.log(Level.INFO, "Failed to deserialize AWS client side encryption config.", exception);
}
}
throw new Exception("Failed to deserialize AWS client side encryption config.")
}
}
The classes involved are:
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import software.amazon.awssdk.regions.Region;
public class AwsKmsConfig extends AwsConfig {
@JsonProperty("key_id")
public final String keyId;
@JsonCreator
public AwsKmsConfig(
@JsonProperty(value = "region", required = true) final Region region,
@JsonProperty(value = "key_id", required = true) final String keyId) {
super(region);
this.keyId = keyId;
}
}
import software.amazon.awssdk.regions.Region;
public class AwsKeyPairConfig extends AwsConfig {
public final String publicKey;
public final String privateKey;
public final PublicKey deserializedPublicKey;
public final PrivateKey deserializedPrivateKey;
/**
* Constructor.
*
* @param region the AWS region in which the S3 objects are stored
* @param publicKey public key to read data in the bucket
* @param privateKey private key to read data in the bucket
*/
@JsonCreator
public AwsKeyPairConfig(
@JsonProperty(value = "region", required = true) final Region region,
@JsonProperty(value = "public_key", required = true) final String publicKey,
@JsonProperty(value = "private_key", required = true) final String privateKey) {
super(region);
this.privateKey = privateKey;
this.publicKey = publicKey;
final Pair<PublicKey, PrivateKey> deserializedKeys =
KeyPairConfig.getDeserializedKeys(publicKey, privateKey);
this.deserializedPublicKey = deserializedKeys.getLeft();
this.deserializedPrivateKey = deserializedKeys.getRight();
}
}
and
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import software.amazon.awssdk.regions.Region;
public class AwsConfig {
@JsonProperty("region")
public final Region region;
@JsonCreator
public AwsConfig(@JsonProperty(value = "region", required = true) final Region region) {
this.region = region;
}
}
What is the equivalent to use in the SDK v2, I did not find anything about it in the documentation, except this opened discussion: #3904 and this issue #2254
Thanks in advance
Links
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/migration-serialization-changes.html