5
5
6
6
import java .lang .reflect .Type ;
7
7
import java .math .BigInteger ;
8
+ import java .util .UUID ;
8
9
import java .util .function .Function ;
9
10
10
11
/**
@@ -17,7 +18,7 @@ class StandaloneRepresentationHandler implements RepresentationHandler {
17
18
// that's not null is already set (and int is auto-initialized with 0)
18
19
private static final Class <?>[] supportedTypes = new Class [] {
19
20
StandaloneRepresentable .class , BigInteger .class , Integer .class , String .class , Boolean .class ,
20
- byte [].class , Enum .class
21
+ byte [].class , UUID . class , Enum .class
21
22
};
22
23
/**
23
24
* Type of the represented object.
@@ -79,6 +80,10 @@ public Object deserializeFromRepresentation(Representation repr, Function<String
79
80
return repr .bytes ().get ();
80
81
}
81
82
83
+ if (type .isAssignableFrom (UUID .class ) && repr instanceof StringRepresentation ) {
84
+ return UUID .fromString (repr .str ().get ());
85
+ }
86
+
82
87
throw new IllegalArgumentException ("Don't know how to recreate " + type .getName () + " from a "
83
88
+ repr .getClass ().getName ());
84
89
}
@@ -129,6 +134,11 @@ public Representation serializeToRepresentation(Object value) {
129
134
return new ByteArrayRepresentation (bytes );
130
135
}
131
136
137
+ if (value instanceof UUID ) {
138
+ UUID uuid = (UUID ) value ;
139
+ return new StringRepresentation (uuid .toString ());
140
+ }
141
+
132
142
throw new IllegalArgumentException ("Do not know how to handle object of type " + value .getClass ().getName ()
133
143
+ ". You may have to add an explicit 'restorer' argument to the @Represented annotation" );
134
144
}
0 commit comments