Skip to content

Serializing Response Objects #2254

@kickroot

Description

@kickroot

What is the supported method of serializing the content from response objects to JSON? The AWS CLI (v2) returns JSON, for example:

$ aws iam list-virtual-mfa-devices
{
    "VirtualMFADevices": [
        {
            "SerialNumber": "arn:aws:iam::<redacted>:mfa/root-account-mfa-device",
            "User": {
                "UserName": "<redacted>",
                "UserId": "<redacted>",
                "Arn": "arn:aws:iam::<redacted>:root",
                "CreateDate": "2020-04-21T16:39:21+00:00",
                "PasswordLastUsed": "2021-01-04T14:42:41+00:00"
            },
            "EnableDate": "2021-01-04T14:49:08+00:00"
        }
    ]
}

How do I achieve the same JSON using aws-sdk-java-v2? Using either a default Jackson ObjectMapper or com.amazonaws.util.json.Jackson.getObjectMapper() results in the following:

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class software.amazon.awssdk.services.iam.model.VirtualMFADevice and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.Collections$UnmodifiableRandomAccessList[0])
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
	at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1277)
	at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:400)
	at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:71)
	at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:33)
	at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:119)
	at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79)
	at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
	at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1513)
	at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1215)
	at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:1085)
	at software.amazon.awssdk.core.util.json.JacksonUtils.toJsonPrettyString(JacksonUtils.java:49)

Describe the issue

It was briefly mentioned here (#1421 (comment)) that the AWS SDK is moving away from Jackson to its own custom serialization libraries, but I can find no mention in the documentation of what these libraries are or how to utilize them.

I can't help but think there must be a clean method of doing this. Writing custom DTOs that are Jackson friendly to map results will not scale.

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-for-stalenessdocumentationThis is a problem with documentation.response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 10 days.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions