Equivalent of `com.amazonaws.util.json.Jackson` in sdk v2
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 51
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:
```java
import com.amazonaws.util.json.Jackson;
...
private static Optional deserializeConfig(final Map 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:
```java
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;
}
}
```
```java
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 deserializedKeys =
KeyPairConfig.getDeserializedKeys(publicKey, privateKey);
this.deserializedPublicKey = deserializedKeys.getLeft();
this.deserializedPrivateKey = deserializedKeys.getRight();
}
}
```
and
```java
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: https://github.com/aws/aws-sdk-java-v2/discussions/3904 and this issue https://github.com/aws/aws-sdk-java-v2/issues/2254
Thanks in advance
### Links
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/migration-serialization-changes.html
Contributor guide
Assessment
This issue has not been assessed yet.