diff --git a/subprojects/micronaut-aws-sdk-dynamodb/src/main/groovy/com/agorapulse/micronaut/aws/dynamodb/DefaultDynamoDBService.groovy b/subprojects/micronaut-aws-sdk-dynamodb/src/main/groovy/com/agorapulse/micronaut/aws/dynamodb/DefaultDynamoDBService.groovy index 6a57dc558..9347a08a3 100644 --- a/subprojects/micronaut-aws-sdk-dynamodb/src/main/groovy/com/agorapulse/micronaut/aws/dynamodb/DefaultDynamoDBService.groovy +++ b/subprojects/micronaut-aws-sdk-dynamodb/src/main/groovy/com/agorapulse/micronaut/aws/dynamodb/DefaultDynamoDBService.groovy @@ -97,6 +97,28 @@ class DefaultDynamoDBService implements DynamoDBService } ) + .addFirstType(Enum, + new ArgumentMarshaller() { + + @Override + AttributeValue marshall(Object obj) { + return obj == null ? null : new AttributeValue().withS(obj.toString()) + } + + }, + new ArgumentUnmarshaller() { + + @Override + void typeCheck(AttributeValue value, Method setter) { } + + @Override + Object unmarshall(AttributeValue value) throws ParseException { + // should not happen + throw new IllegalStateException('Cannot unmarshall Enum, add @DynamoDBConvertedEnum annotation to the field') + } + + } + ) .build() // Specific ranges ending with 'Index' are String concatenated indexes, diff --git a/subprojects/micronaut-aws-sdk-dynamodb/src/test/groovy/com/agorapulse/micronaut/aws/dynamodb/DynamoDBEntity.java b/subprojects/micronaut-aws-sdk-dynamodb/src/test/groovy/com/agorapulse/micronaut/aws/dynamodb/DynamoDBEntity.java index b0ac551f4..0e2da0431 100644 --- a/subprojects/micronaut-aws-sdk-dynamodb/src/test/groovy/com/agorapulse/micronaut/aws/dynamodb/DynamoDBEntity.java +++ b/subprojects/micronaut-aws-sdk-dynamodb/src/test/groovy/com/agorapulse/micronaut/aws/dynamodb/DynamoDBEntity.java @@ -43,6 +43,9 @@ public class DynamoDBEntity { Integer number = 0; + @DynamoDBTypeConvertedEnum + State state = State.UNKNOWN; + public String getParentId() { return parentId; } @@ -92,6 +95,14 @@ public void setGlobalIndex(String globalIndex) { // ignore } + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + //CHECKSTYLE:OFF @Override public boolean equals(Object o) { diff --git a/subprojects/micronaut-aws-sdk-dynamodb/src/test/groovy/com/agorapulse/micronaut/aws/dynamodb/State.java b/subprojects/micronaut-aws-sdk-dynamodb/src/test/groovy/com/agorapulse/micronaut/aws/dynamodb/State.java new file mode 100644 index 000000000..c7a98f7fd --- /dev/null +++ b/subprojects/micronaut-aws-sdk-dynamodb/src/test/groovy/com/agorapulse/micronaut/aws/dynamodb/State.java @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2018-2024 Agorapulse. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.agorapulse.micronaut.aws.dynamodb; + +public enum State { + + OPEN, + CLOSED, + IN_PROGRESS, + CANCELLED, + UNKNOWN; + +}