Package org.carrot2.attrs
Class Attrs
java.lang.Object
org.carrot2.attrs.Attrs
Static utility methods for converting between
AcceptingVisitor
and Map
s.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionextract
(AcceptingVisitor instance) Extracts just the attributes of an instance (no top-level type information is preserved).extract
(AcceptingVisitor instance, Function<Object, String> classToName) Extracts just the attributes of an instance (no top-level type information is preserved).static <E extends AcceptingVisitor>
EConvert a map to an instance of a class.static <E extends AcceptingVisitor>
EConvert a map to an instance of a class.static <E extends AcceptingVisitor>
EfromMap
(Class<E> clazz, Supplier<? extends E> defaultImplSupplier, Map<String, Object> map, Function<String, Object> nameToClass) Convert a map to an instance of a class.static <E extends AcceptingVisitor>
EConvert a map to an instance of a class.static <E extends AcceptingVisitor>
EPopulates a given instance with the values from the map.static <E extends AcceptingVisitor>
EPopulates a given instance with the values from the map.static String
toJson
(AcceptingVisitor composite) Converts an instance (recursively) to JSON.static String
toJson
(AcceptingVisitor composite, Function<Object, String> classToName) Converts an instance (recursively) to JSON.static String
toJson
(AcceptingVisitor composite, ClassNameMapper classNameMapper) Converts an instance (recursively) to JSON.toMap
(AcceptingVisitor composite) Convert an instance to a map.toMap
(AcceptingVisitor composite, Function<Object, String> classToName) Convert an instance to a map.
-
Constructor Details
-
Attrs
public Attrs()
-
-
Method Details
-
toMap
Convert an instance to a map. The output map will contain the type of the instance and can be recreated withfromMap(Class, Map)
.This method uses default class name mappings.
- See Also:
-
toMap
public static Map<String,Object> toMap(AcceptingVisitor composite, Function<Object, String> classToName) Convert an instance to a map. The output map will contain the type of the instance and can be recreated withfromMap(Class, Map)
.- Parameters:
classToName
- Class to name mapping provider.- See Also:
-
fromMap
public static <E extends AcceptingVisitor> E fromMap(Class<? extends E> clazz, Map<String, Object> map) Convert a map to an instance of a class.This method uses default class name mappings.
- See Also:
-
fromMap
public static <E extends AcceptingVisitor> E fromMap(Class<E> clazz, Map<String, Object> map, Function<String, Object> nameToClass) Convert a map to an instance of a class.- Parameters:
nameToClass
- Name to new class instance supplier.- See Also:
-
fromMap
public static <E extends AcceptingVisitor> E fromMap(Class<E> clazz, Supplier<? extends E> defaultImplSupplier, Map<String, Object> map, Function<String, Object> nameToClass) Convert a map to an instance of a class.- Parameters:
nameToClass
- Name to new class instance supplier.- Since:
- 4.1.0
- See Also:
-
fromMap
public static <E extends AcceptingVisitor> E fromMap(Class<E> clazz, Supplier<? extends E> defaultImplSupplier, Map<String, Object> map) Convert a map to an instance of a class.- Since:
- 4.1.0
- See Also:
-
extract
public static Map<String,Object> extract(AcceptingVisitor instance, Function<Object, String> classToName) Extracts just the attributes of an instance (no top-level type information is preserved).- Parameters:
classToName
- Class to name mapping provider.
-
extract
Extracts just the attributes of an instance (no top-level type information is preserved).This method uses default class name mappings.
-
populate
Populates a given instance with the values from the map.This method uses default class name mappings.
- See Also:
-
populate
public static <E extends AcceptingVisitor> E populate(E instance, Map<String, Object> map, Function<String, Object> nameToClass) Populates a given instance with the values from the map.- Parameters:
nameToClass
- Name to new class instance supplier.- See Also:
-
toJson
Converts an instance (recursively) to JSON.This method uses default class name mappings (
AliasMapper.SPI_DEFAULTS
).- Since:
- 4.1.0
-
toJson
Converts an instance (recursively) to JSON. -
toJson
Converts an instance (recursively) to JSON.- Parameters:
classToName
- Class to name mapping provider.
-