Skip to content

Commit e4a2313

Browse files
authored
Merge pull request #153 from cryptimeleon/develop
2 parents 7d6fcd9 + adafc51 commit e4a2313

4 files changed

Lines changed: 26 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Latest]
88

9+
## [3.1.0]
10+
11+
### Added
12+
- UUIDs can now be serialized to representation.
913

1014
## [3.0.1]
1115

@@ -66,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6670
- Initial release
6771

6872

69-
[Latest]: https://github.com/cryptimeleon/math/compare/v3.0.1...HEAD
73+
[Latest]: https://github.com/cryptimeleon/math/compare/v3.1.0...HEAD
74+
[3.1.0]: https://github.com/cryptimeleon/math/compare/v3.0.0...v3.0.1
7075
[3.0.1]: https://github.com/cryptimeleon/math/compare/v3.0.0...v3.0.1
7176
[3.0.0]: https://github.com/cryptimeleon/math/compare/v2.1.0...v3.0.0
7277
[2.1.0]: https://github.com/cryptimeleon/math/compare/v2.0.0...v2.1.0

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
group = 'org.cryptimeleon'
99
archivesBaseName = project.name
1010
boolean isRelease = project.hasProperty("release")
11-
version = '3.0.3' + (isRelease ? "" : "-SNAPSHOT")
11+
version = '3.1.0' + (isRelease ? "" : "-SNAPSHOT")
1212

1313
sourceCompatibility = 1.8
1414
targetCompatibility = 1.8

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
* For more information, consult the <a href="https://upbcuk.github.io/docs/representations.html">documentation</a>.
5959
*/
6060
public class ReprUtil {
61+
static final String[] primitiveTypes = new String[] {"byte", "short", "int", "long", "float", "double", "boolean", "char"};
6162
static Pattern methodCallSeparator = Pattern.compile("::");
6263
/**
6364
* Maps representation restorer identifiers to the corresponding {@code RepresentationRestorer} instances.
@@ -438,6 +439,9 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
438439
);
439440
}
440441

442+
if (Arrays.asList(primitiveTypes).contains(type.getTypeName()))
443+
throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)");
444+
441445
throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName()
442446
+ " using restorer String \"" + restorerString + "\"");
443447
}
@@ -451,7 +455,6 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
451455
protected static RepresentationHandler getHandlerWithoutRestorerString(Type type) {
452456
// For generic type we need to extract the raw type. Only for StandaloneRepresentable though, as stuff
453457
// like list and map handling can handle generic types by themselves.
454-
// TODO: What about DependentRepresentations?
455458
Type rawType = type;
456459
if (type instanceof ParameterizedType) {
457460
rawType = ((ParameterizedType) type).getRawType();
@@ -478,8 +481,11 @@ protected static RepresentationHandler getHandlerWithoutRestorerString(Type type
478481
return new MapRepresentationHandler(getHandlerWithoutRestorerString(keyType), getHandlerWithoutRestorerString(valueType), type);
479482
}
480483

484+
if (Arrays.asList(primitiveTypes).contains(type.getTypeName()))
485+
throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)");
486+
481487
throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName()
482-
+ " using empty restorer String (you can add one within the @Represented annotation)");
488+
+ " using empty restorer String (you can add one within the @Represented annotation to manually specify how to recreate this type)");
483489
}
484490

485491
/**

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)