DynamoDBMapper for java.time.LocalDateTime

I am using java.time.LocalDateTime in my java application. I also try to use DynamoDBMapper, and through the annotation I save the variable LocalDateTime. Unfortunately, I get the following error:

DynamoDBMappingException: Unsupported type: class java.time.LocalDateTime

Is there any way to get this mapping without using DynamoDBMarshalling?

+7
source share
2 answers

Despite what I said, I found it simple enough to use DynamoDBMarshallingfor marshaling and out of line. Here is my code snippet and AWS link :

class MyClass {

    ...

    @DynamoDBMarshalling(marshallerClass = LocalDateTimeConverter.class)
    public LocalDateTime getStartTime() {
        return startTime;
    }

    ...
    static public class LocalDateTimeConverter implements DynamoDBMarshaller<LocalDateTime> {

        @Override
        public String marshall(LocalDateTime time) {
            return time.toString();
        }

        @Override
        public LocalDateTime unmarshall(Class<LocalDateTime> dimensionType, String stringValue) {
            return LocalDateTime.parse(stringValue);
        }
    }
}
+2
source

AWS DynamoDB Java SDK java.time.LocalDateTime - .

, DynamoDBTypeConverted, 1.11.20 AWS Java SDK. DynamoDBMarshalling .

:

class MyClass {

    ...

    @DynamoDBTypeConverted( converter = LocalDateTimeConverter.class )
    public LocalDateTime getStartTime() {

        return startTime;
    }

    ...

    static public class LocalDateTimeConverter implements DynamoDBTypeConverter<String, LocalDateTime> {

        @Override
        public String convert( final LocalDateTime time ) {

            return time.toString();
        }

        @Override
        public LocalDateTime unconvert( final String stringValue ) {

            return LocalDateTime.parse(stringValue);
        }
    }
}

ISO-8601: 2016-10-20T16:26:47.299.

+15

All Articles