Skip to content

Commit

Permalink
Merge pull request #152 from cryptimeleon/feature/standalone-repr-uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBobolz authored Nov 18, 2021
2 parents a5e7b7b + e10c750 commit f57a9c5
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.lang.reflect.Type;
import java.math.BigInteger;
import java.util.UUID;
import java.util.function.Function;

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

if (type.isAssignableFrom(UUID.class) && repr instanceof StringRepresentation) {
return UUID.fromString(repr.str().get());
}

throw new IllegalArgumentException("Don't know how to recreate " + type.getName() + " from a "
+ repr.getClass().getName());
}
Expand Down Expand Up @@ -129,6 +134,11 @@ public Representation serializeToRepresentation(Object value) {
return new ByteArrayRepresentation(bytes);
}

if (value instanceof UUID) {
UUID uuid = (UUID) value;
return new StringRepresentation(uuid.toString());
}

throw new IllegalArgumentException("Do not know how to handle object of type " + value.getClass().getName()
+ ". You may have to add an explicit 'restorer' argument to the @Represented annotation");
}
Expand Down

0 comments on commit f57a9c5

Please sign in to comment.