skip to Main Content

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


  1. Chosen as BEST ANSWER

    I think the answer is given here: https://github.com/aws/aws-sdk-java-v2/issues/2254

    To serialize:

    String taskDefinitionJson = new ObjectMapper().writeValueAsString(
            taskDefinition.toBuilder());
    

    To deserialize:

    TaskDefinition taskDefinition = new ObjectMapper().readValue(
            taskDefinitionJson,
            TaskDefinition.serializableBuilderClass())
        .build();
    

  2. in the docs, there is a method called serializableBuilderClass()

    Try using that. I’d imagine the code would be something like:

    TaskDefinition.serializableBuilderClass().build()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search