diff --git a/src/main/java/org/cryptimeleon/math/serialization/annotations/ReprUtil.java b/src/main/java/org/cryptimeleon/math/serialization/annotations/ReprUtil.java index f21d6534..29e00372 100644 --- a/src/main/java/org/cryptimeleon/math/serialization/annotations/ReprUtil.java +++ b/src/main/java/org/cryptimeleon/math/serialization/annotations/ReprUtil.java @@ -58,6 +58,7 @@ * For more information, consult the documentation. */ public class ReprUtil { + static final String[] primitiveTypes = new String[] {"byte", "short", "int", "long", "float", "double", "boolean", "char"}; static Pattern methodCallSeparator = Pattern.compile("::"); /** * Maps representation restorer identifiers to the corresponding {@code RepresentationRestorer} instances. @@ -438,6 +439,9 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S ); } + if (Arrays.asList(primitiveTypes).contains(type.getTypeName())) + throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)"); + throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName() + " using restorer String \"" + restorerString + "\""); } @@ -451,7 +455,6 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S protected static RepresentationHandler getHandlerWithoutRestorerString(Type type) { // For generic type we need to extract the raw type. Only for StandaloneRepresentable though, as stuff // like list and map handling can handle generic types by themselves. - // TODO: What about DependentRepresentations? Type rawType = type; if (type instanceof ParameterizedType) { rawType = ((ParameterizedType) type).getRawType(); @@ -478,8 +481,11 @@ protected static RepresentationHandler getHandlerWithoutRestorerString(Type type return new MapRepresentationHandler(getHandlerWithoutRestorerString(keyType), getHandlerWithoutRestorerString(valueType), type); } + if (Arrays.asList(primitiveTypes).contains(type.getTypeName())) + throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)"); + throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName() - + " using empty restorer String (you can add one within the @Represented annotation)"); + + " using empty restorer String (you can add one within the @Represented annotation to manually specify how to recreate this type)"); } /**