Skip to content

Commit f57a9c5

Browse files
authored
Merge pull request #152 from cryptimeleon/feature/standalone-repr-uuid
2 parents a5e7b7b + e10c750 commit f57a9c5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/org/cryptimeleon/math/serialization/annotations/StandaloneRepresentationHandler.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.lang.reflect.Type;
77
import java.math.BigInteger;
8+
import java.util.UUID;
89
import java.util.function.Function;
910

1011
/**
@@ -17,7 +18,7 @@ class StandaloneRepresentationHandler implements RepresentationHandler {
1718
// that's not null is already set (and int is auto-initialized with 0)
1819
private static final Class<?>[] supportedTypes = new Class[] {
1920
StandaloneRepresentable.class, BigInteger.class, Integer.class, String.class, Boolean.class,
20-
byte[].class, Enum.class
21+
byte[].class, UUID.class, Enum.class
2122
};
2223
/**
2324
* Type of the represented object.
@@ -79,6 +80,10 @@ public Object deserializeFromRepresentation(Representation repr, Function<String
7980
return repr.bytes().get();
8081
}
8182

83+
if (type.isAssignableFrom(UUID.class) && repr instanceof StringRepresentation) {
84+
return UUID.fromString(repr.str().get());
85+
}
86+
8287
throw new IllegalArgumentException("Don't know how to recreate " + type.getName() + " from a "
8388
+ repr.getClass().getName());
8489
}
@@ -129,6 +134,11 @@ public Representation serializeToRepresentation(Object value) {
129134
return new ByteArrayRepresentation(bytes);
130135
}
131136

137+
if (value instanceof UUID) {
138+
UUID uuid = (UUID) value;
139+
return new StringRepresentation(uuid.toString());
140+
}
141+
132142
throw new IllegalArgumentException("Do not know how to handle object of type " + value.getClass().getName()
133143
+ ". You may have to add an explicit 'restorer' argument to the @Represented annotation");
134144
}

0 commit comments

Comments
 (0)