I'm trying to serialize/deserialize the DynamoDB V2 AttributeValue class using Jackson.
It is setup as an immutable class with a Builder and the builder has a private constructor. In order to create a builder, you need to call AttributeValue.builder().
I have no control over this class, so I want to use Jackson mixins.
I've used the @JsonDeserialize(builder = AttributeValue.Builder::class) and registered the mixin:
@JsonDeserialize(builder = AttributeValue.Builder::class)
interface AttributeValueMixin {
}
private val mapper = jacksonObjectMapper()
.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY)
.addMixIn(AttributeValue::class.java, AttributeValueMixin::class.java)
However, Jackson is trying to use the default constructor of the AttributeValue.Builder and it can't since it doesn't have one.
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
software.amazon.awssdk.services.dynamodb.model.AttributeValue$Builder(no Creators, like default construct, exist)
How can I get Jackson to use the AttributeValue.builder() factory function? Or any other ideas on how to use Jackson to serialize/deserialize this AttributeValue class?