Package org.drasyl.pipeline.codec
Class TypeValidator
java.lang.Object
org.drasyl.pipeline.codec.TypeValidator
The
TypeValidator
allows to define which classes and packages may be handled by a codec.
It thus represents a marshalling whitelist.-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a class to the list.void
addPackage
(String p) Adds a package to the list.static boolean
Checks ifclazz
is a subclass ofsuperClass
.static TypeValidator
of
(List<String> classes, List<String> packages, boolean allowAllPrimitives, boolean allowArrayOfTypes) static TypeValidator
ofInboundValidator
(DrasylConfig config) static TypeValidator
ofOutboundValidator
(DrasylConfig config) void
removeClass
(Class<?> clazz) Removes a class from the list.void
Removes a package from the list.static Class<?>
unwrapArrayComponentType
(Class<?> clazzToUnwrap) Returns the Class representing the component type of an array.boolean
Validates a givenClass
if it is allowed or not.
-
Method Details
-
addClass
Adds a class to the list.- Parameters:
clazz
- class that should be added
-
addPackage
Adds a package to the list.- Parameters:
p
- package that should be added
-
removeClass
Removes a class from the list.- Parameters:
clazz
- class that should be removed
-
removePackage
Removes a package from the list.- Parameters:
p
- package that should be removed
-
validate
Validates a givenClass
if it is allowed or not.- Parameters:
clazzToTest
- class that should be validated- Returns:
- if the class is allowed or not
-
isTypeOf
Checks ifclazz
is a subclass ofsuperClass
.- Parameters:
clazz
- possible subclasssuperClass
- the superclass- Returns:
- if clazz is a subclass of superClass true, otherwise false
-
unwrapArrayComponentType
Returns the Class representing the component type of an array. If this class does not represent an array class this method returns theclazzToUnwrap
.- Parameters:
clazzToUnwrap
- class that should be unwrapped- Returns:
- the
Class
representing the component type of this class if this class is an array, otherwise the input is returned
-
ofInboundValidator
-
of
public static TypeValidator of(List<String> classes, List<String> packages, boolean allowAllPrimitives, boolean allowArrayOfTypes) -
ofOutboundValidator
-