With the AWS Java SDK V1, all of the classes were normal POJOs with standard getters and setters, so using Jackson you could just serialize/deserialize them easily.
Example:
TaskDefinition taskDefinition = ecsClient.describeTaskDefinition(new DescribeTaskDefinitionRequest().withTaskDefinition("myTaskDefinition")).getTaskDefinition();
System.out.println(new ObjectMapper().writeValueAsString(taskDefinition));
Result:
{"taskDefinitionArn":"...","containerDefinitions":[...]}
But when I try this same thing with the AWS Java SDK V2, it results in an empty JSON object.
Example:
TaskDefinition taskDefinition = ecsClient.describeTaskDefinition(DescribeTaskDefinitionRequest.builder().taskDefinition("myTaskDefinition").build()).taskDefinition();
System.out.println(new ObjectMapper().writeValueAsString(taskDefinition));
Result:
{}
And when I try to deserialize using Jackson, it results in an error:
Cannot construct instance of `software.amazon.awssdk.services.ecs.model.TaskDefinition` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
2
Answers
I think the answer is given here: https://github.com/aws/aws-sdk-java-v2/issues/2254
To serialize:
To deserialize:
in the docs, there is a method called serializableBuilderClass()
Try using that. I’d imagine the code would be something like: