58
58
* For more information, consult the <a href="https://upbcuk.github.io/docs/representations.html">documentation</a>.
59
59
*/
60
60
public class ReprUtil {
61
+ static final String [] primitiveTypes = new String [] {"byte" , "short" , "int" , "long" , "float" , "double" , "boolean" , "char" };
61
62
static Pattern methodCallSeparator = Pattern .compile ("::" );
62
63
/**
63
64
* Maps representation restorer identifiers to the corresponding {@code RepresentationRestorer} instances.
@@ -438,6 +439,9 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
438
439
);
439
440
}
440
441
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
+
441
445
throw new IllegalArgumentException ("Don't know how to handle type " + type .getTypeName ()
442
446
+ " using restorer String \" " + restorerString + "\" " );
443
447
}
@@ -451,7 +455,6 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
451
455
protected static RepresentationHandler getHandlerWithoutRestorerString (Type type ) {
452
456
// For generic type we need to extract the raw type. Only for StandaloneRepresentable though, as stuff
453
457
// like list and map handling can handle generic types by themselves.
454
- // TODO: What about DependentRepresentations?
455
458
Type rawType = type ;
456
459
if (type instanceof ParameterizedType ) {
457
460
rawType = ((ParameterizedType ) type ).getRawType ();
@@ -478,8 +481,11 @@ protected static RepresentationHandler getHandlerWithoutRestorerString(Type type
478
481
return new MapRepresentationHandler (getHandlerWithoutRestorerString (keyType ), getHandlerWithoutRestorerString (valueType ), type );
479
482
}
480
483
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
+
481
487
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 )" );
483
489
}
484
490
485
491
/**
0 commit comments