1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.socialsignin.spring.data.dynamodb.marshaller;
17
18 import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshaller;
19 import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTypeConverter;
20 import org.springframework.util.StringUtils;
21
22 import java.text.DateFormat;
23 import java.text.ParseException;
24 import java.util.Date;
25
26 @SuppressWarnings("deprecation")
27 public abstract class DateDynamoDBMarshaller implements DynamoDBTypeConverter<String, Date>, DynamoDBMarshaller<Date> {
28
29 public abstract DateFormat getDateFormat();
30
31 @Override
32 public String convert(Date object) {
33 return marshall(object);
34 }
35
36 @Override
37 public String marshall(Date getterReturnResult) {
38 if (getterReturnResult == null) {
39 return null;
40 } else {
41 return getDateFormat().format(getterReturnResult);
42 }
43 }
44
45 @Override
46 public Date unconvert(String object) {
47 return unmarshall(Date.class, object);
48 }
49
50 @Override
51 public Date unmarshall(Class<Date> clazz, String obj) {
52 if (StringUtils.isEmpty(obj)) {
53 return null;
54 } else {
55 try {
56 return getDateFormat().parse(obj);
57 } catch (ParseException e) {
58 throw new RuntimeException(e);
59 }
60 }
61 }
62
63 }