Class TypeValidator

java.lang.Object
org.drasyl.pipeline.codec.TypeValidator

public class TypeValidator extends Object
The TypeValidator allows to define which classes and packages may be handled by a codec. It thus represents a marshalling whitelist.
  • Method Details

    • addClass

      public void addClass(Class<?>... clazz)
      Adds a class to the list.
      Parameters:
      clazz - class that should be added
    • addPackage

      public void addPackage(String p)
      Adds a package to the list.
      Parameters:
      p - package that should be added
    • removeClass

      public void removeClass(Class<?> clazz)
      Removes a class from the list.
      Parameters:
      clazz - class that should be removed
    • removePackage

      public void removePackage(String p)
      Removes a package from the list.
      Parameters:
      p - package that should be removed
    • validate

      public boolean validate(Class<?> clazzToTest)
      Validates a given Class if it is allowed or not.
      Parameters:
      clazzToTest - class that should be validated
      Returns:
      if the class is allowed or not
    • isTypeOf

      public static boolean isTypeOf(Class<?> clazz, Class<?> superClass)
      Checks if clazz is a subclass of superClass.
      Parameters:
      clazz - possible subclass
      superClass - the superclass
      Returns:
      if clazz is a subclass of superClass true, otherwise false
    • unwrapArrayComponentType

      public static Class<?> unwrapArrayComponentType(Class<?> clazzToUnwrap)
      Returns the Class representing the component type of an array. If this class does not represent an array class this method returns the clazzToUnwrap.
      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

      public static TypeValidator ofInboundValidator(DrasylConfig config)
    • of

      public static TypeValidator of(List<String> classes, List<String> packages, boolean allowAllPrimitives, boolean allowArrayOfTypes)
    • ofOutboundValidator

      public static TypeValidator ofOutboundValidator(DrasylConfig config)