Class ClassConverter
- java.lang.Object
-
- org.apache.johnzon.mapper.converter.ClassConverter
-
- All Implemented Interfaces:
Converter<Class<?>>,MapperConverter
public class ClassConverter extends Object implements Converter<Class<?>>
Maps aClassto/from its name.Deserializing a class name means loading the class the incoming document asks for, so this converter is not registered by default and must be registered explicitly - see
MapperBuilder#addConverter- with the set of classes it is allowed to load. Both allow-lists default to empty, ie deserialization always fails until they are configured.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.johnzon.mapper.Converter
Converter.TypeAccess
-
-
Field Summary
Fields Modifier and Type Field Description private Collection<String>allowedClassesprivate Collection<String>allowedPrefixes
-
Constructor Summary
Constructors Constructor Description ClassConverter()Serialization only, any incoming class name is rejected.ClassConverter(Collection<String> allowedClasses, Collection<String> allowedPrefixes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Collection<String>copy(Collection<String> values)Class<?>fromString(String text)private booleanisAllowed(String name)StringtoString(Class<?> instance)
-
-
-
Field Detail
-
allowedClasses
private final Collection<String> allowedClasses
-
allowedPrefixes
private final Collection<String> allowedPrefixes
-
-
Constructor Detail
-
ClassConverter
public ClassConverter()
Serialization only, any incoming class name is rejected.
-
ClassConverter
public ClassConverter(Collection<String> allowedClasses, Collection<String> allowedPrefixes)
- Parameters:
allowedClasses- the fully qualified names which can be loaded from the incoming document.allowedPrefixes- the prefixes - generally packages - a class name must start with to be loaded.
-
-
Method Detail
-
fromString
public Class<?> fromString(String text)
- Specified by:
fromStringin interfaceConverter<Class<?>>
-
isAllowed
private boolean isAllowed(String name)
-
copy
private static Collection<String> copy(Collection<String> values)
-
-