File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
src/main/java/de/zalando/typemapper/core/fieldMapper Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
import java .util .Date ;
6
6
import java .util .Map ;
7
+ import java .util .UUID ;
7
8
import java .util .concurrent .ConcurrentHashMap ;
8
9
9
10
import de .zalando .typemapper .core .ValueTransformer ;
@@ -62,6 +63,9 @@ public class FieldMapperRegister {
62
63
63
64
final FieldMapper hstoreMapper = new HStoreFieldMapper ();
64
65
FieldMapperRegister .register (Map .class , hstoreMapper );
66
+
67
+ final FieldMapper uuidMapper = new UUIDFieldMapper ();
68
+ FieldMapperRegister .register (UUID .class , uuidMapper );
65
69
}
66
70
67
71
@ SuppressWarnings ("rawtypes" )
Original file line number Diff line number Diff line change
1
+ package de .zalando .typemapper .core .fieldMapper ;
2
+
3
+ import org .slf4j .Logger ;
4
+ import org .slf4j .LoggerFactory ;
5
+
6
+ import java .util .UUID ;
7
+
8
+ /**
9
+ * Created by akushsky on 27.08.2015.
10
+ */
11
+ public class UUIDFieldMapper implements FieldMapper {
12
+
13
+ private static final Logger LOG = LoggerFactory .getLogger (UUIDFieldMapper .class );
14
+
15
+ @ Override
16
+ public Object mapField (String string , Class <?> clazz ) {
17
+ if (string == null ) {
18
+ return null ;
19
+ }
20
+
21
+ try {
22
+ return UUID .fromString (string );
23
+ } catch (IllegalArgumentException e ) {
24
+ LOG .error ("Could not convert {} to UUID." , string );
25
+ return null ;
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments