Class TestJson
java.lang.Object
de.iip_ecosphere.platform.support.json.Json
test.de.iip_ecosphere.platform.support.json.TestJson
- Direct Known Subclasses:
TestJson.TestJson4All
public class TestJson
extends de.iip_ecosphere.platform.support.json.Json
Implements the JSON interface by Jackson.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProperty exclusion modifier to simulateInclude.static classRenames properties.static classGeneric enum deserializer.static classSpecifies the mapping of an enumeration for serialization/deserialization.static classWriter to prevent writing null properties if disabled byInclude.private static classInternal type to obtain a typed List from JSON.static classA property naming strategy exactly using the given names as JSON and Java field/getter/setter names.private static classInternal type to obtain a typed Map from JSON.static classBasic annotation introspector for abstracting oktoflow data annotations, in particularConfiguredNameandIgnore.static classA handler for optional fields.private classSelf-configuring Json implementation based on provided types.Nested classes/interfaces inherited from class de.iip_ecosphere.platform.support.json.Json
de.iip_ecosphere.platform.support.json.Json.EnumMapping<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolverA type resolver for "Impl" classes in "iip.".private com.fasterxml.jackson.databind.ObjectMapperprivate com.fasterxml.jackson.databind.ObjectWriter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionde.iip_ecosphere.platform.support.json.JsonconfigureExceptFieldsFilter(String filterId, String... fieldNames) configureFor(com.fasterxml.jackson.databind.ObjectMapper mapper, TestJson.OktoAnnotationIntrospector introspector, Class<?> cls) Configures the given class for through the abstracted annotations.de.iip_ecosphere.platform.support.json.JsonconfigureFor(Class<?> cls) configureLazy(com.fasterxml.jackson.databind.ObjectMapper mapper, TestJson.OktoAnnotationIntrospector introspector, Set<Object> ignore) Configures the given mapper for lazy serialization ignoring given classes and members.de.iip_ecosphere.platform.support.json.JsonconfigureLazy(Set<Object> ignore) <T> TconvertValue(Object value, Class<T> cls) protected de.iip_ecosphere.platform.support.json.JsonArrayBuilder<T> de.iip_ecosphere.platform.support.json.Json.EnumMapping<T> createEnumMapping(Class<T> type, Map<String, T> mapping) protected de.iip_ecosphere.platform.support.json.JsonGeneratorcreateGeneratorImpl(Writer writer) de.iip_ecosphere.platform.support.json.JsoncreateInstanceImpl(boolean considerAnnotations) static <T> de.iip_ecosphere.platform.support.json.IOIterator<T> createIterator(com.fasterxml.jackson.databind.ObjectMapper mapper, InputStream stream, Class<T> cls) Creates an iterator over the information instreamassuming a heterogeneous collection ofcls.<T> de.iip_ecosphere.platform.support.json.IOIterator<T> createIterator(InputStream stream, Class<T> cls) protected de.iip_ecosphere.platform.support.json.JsonObjectBuilderprotected de.iip_ecosphere.platform.support.json.JsonObjectcreateObjectImpl(Reader reader) static com.fasterxml.jackson.databind.ObjectMapperdeclareEnums(com.fasterxml.jackson.databind.ObjectMapper mapper, de.iip_ecosphere.platform.support.json.Json.EnumMapping<?>... mappings) Declares enumerations on the specified mapper.de.iip_ecosphere.platform.support.json.JsondeclareEnums(de.iip_ecosphere.platform.support.json.Json.EnumMapping<?>... mappings) static com.fasterxml.jackson.databind.ObjectMapperdefineFields(com.fasterxml.jackson.databind.ObjectMapper mapper, String... fieldNames) Defines a mapping of JSON names to Java field names using exactly the given names.de.iip_ecosphere.platform.support.json.JsondefineFields(String... fieldNames) static com.fasterxml.jackson.databind.ObjectMapperdefineOptionals(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<?> cls, String... fieldNames) Defines the givenfieldNamesas optional during deserialization.de.iip_ecosphere.platform.support.json.JsondefineOptionals(Class<?> cls, String... fieldNames) exceptFields(com.fasterxml.jackson.databind.ObjectMapper mapper, TestJson.OktoAnnotationIntrospector introspector, String... fieldNames) Returns an object writer for a mapper that applies a filter onfieldNamesto be excluded.de.iip_ecosphere.platform.support.json.JsonexceptFields(String... fieldNames) de.iip_ecosphere.platform.support.json.JsonfailOnUnknownProperties(boolean fail) de.iip_ecosphere.platform.support.json.JsonfilterAllExceptFields(String... fieldNames) <R> Rprivate static voidhandleAnnotations(String propName, AccessibleObject obj, Map<String, String> renames, Set<String> nonNullInclude) Collects data on supported annotations (ConfiguredName,JsonPropertyInclude) for an accessible object.de.iip_ecosphere.platform.support.json.Jsonstatic com.fasterxml.jackson.databind.ObjectMapperhandleIipDataClasses(com.fasterxml.jackson.databind.ObjectMapper mapper) Configures a Jackson object mapper for IIP conventions.private static booleanReturns whether the specified configured namecfgNamerepresents a renaming ofpropName.<R> List<R> listFromJson(Object json, Class<R> cls) <K,V> Map <K, V> mapFromJson(Object json, Class<K> keyCls, Class<K> valueCls) protected de.iip_ecosphere.platform.support.json.JsonIteratorparseImpl(byte[] data) protected de.iip_ecosphere.platform.support.json.JsonIterator<T> T<T> Tprivate static TestJson.OktoAnnotationIntrospectorsetAnnotationIntrospector(com.fasterxml.jackson.databind.ObjectMapper mapper, TestJson.OktoAnnotationIntrospector introspector, Consumer<TestJson.OktoAnnotationIntrospector> configurer) Sets the annotation introspector onmapper.byte[]writeValueAsBytes(Object value) writeValueAsString(Object value) Methods inherited from class de.iip_ecosphere.platform.support.json.Json
createArrayBuilder, createEnumMapping, createEnumValueMap, createEnumValueMapping, createGenerator, createInstance, createInstance, createInstance, createInstance4All, createObject, createObject, createObject, createObjectBuilder, fromJsonDflt, listFromJsonDflt, mapFromJsonDflt, parse, parse, readValueDflt, readValueDflt, setPrototype, toJsonDflt, toJsonQuiet, writeValueAsBytesDflt, writeValueAsStringDflt
-
Field Details
-
IIP_TYPE_RESOLVER
public static final com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver IIP_TYPE_RESOLVERA type resolver for "Impl" classes in "iip.". -
mapper
private com.fasterxml.jackson.databind.ObjectMapper mapper -
writer
private com.fasterxml.jackson.databind.ObjectWriter writer -
introspector
-
-
Constructor Details
-
TestJson
public TestJson()
-
-
Method Details
-
createInstanceImpl
public de.iip_ecosphere.platform.support.json.Json createInstanceImpl(boolean considerAnnotations) - Specified by:
createInstanceImplin classde.iip_ecosphere.platform.support.json.Json
-
toJson
- Specified by:
toJsonin classde.iip_ecosphere.platform.support.json.Json- Throws:
IOException
-
fromJson
- Specified by:
fromJsonin classde.iip_ecosphere.platform.support.json.Json- Throws:
IOException
-
listFromJson
- Specified by:
listFromJsonin classde.iip_ecosphere.platform.support.json.Json
-
mapFromJson
- Specified by:
mapFromJsonin classde.iip_ecosphere.platform.support.json.Json
-
readValue
- Specified by:
readValuein classde.iip_ecosphere.platform.support.json.Json- Throws:
IOException
-
readValue
- Specified by:
readValuein classde.iip_ecosphere.platform.support.json.Json- Throws:
IOException
-
writeValueAsBytes
- Specified by:
writeValueAsBytesin classde.iip_ecosphere.platform.support.json.Json- Throws:
IOException
-
configureFor
public static TestJson.OktoAnnotationIntrospector configureFor(com.fasterxml.jackson.databind.ObjectMapper mapper, TestJson.OktoAnnotationIntrospector introspector, Class<?> cls) Configures the given class for through the abstracted annotations.- Parameters:
mapper- the mapper to be configuredintrospector- the current introspector, may be nullcls- the class to be configured- Returns:
- the configuring annotation introspector
-
handleAnnotations
private static void handleAnnotations(String propName, AccessibleObject obj, Map<String, String> renames, Set<String> nonNullInclude) Collects data on supported annotations (ConfiguredName,JsonPropertyInclude) for an accessible object.- Parameters:
propName- the property nameobj- the accessible objectrenames- the property renamings (original name, new name)nonNullInclude- the properties to not include if their value is null
-
isRename
Returns whether the specified configured namecfgNamerepresents a renaming ofpropName.- Parameters:
cfgName- the configured namepropName- the property name- Returns:
truefor renaming,falsefor no renaming
-
configureFor
- Specified by:
configureForin classde.iip_ecosphere.platform.support.json.Json
-
handleIipDataClasses
public static com.fasterxml.jackson.databind.ObjectMapper handleIipDataClasses(com.fasterxml.jackson.databind.ObjectMapper mapper) Configures a Jackson object mapper for IIP conventions.- Parameters:
mapper- the mapper to be configured- Returns:
mapper
-
handleIipDataClasses
public de.iip_ecosphere.platform.support.json.Json handleIipDataClasses()- Specified by:
handleIipDataClassesin classde.iip_ecosphere.platform.support.json.Json
-
defineOptionals
public static com.fasterxml.jackson.databind.ObjectMapper defineOptionals(com.fasterxml.jackson.databind.ObjectMapper mapper, Class<?> cls, String... fieldNames) Defines the givenfieldNamesas optional during deserialization.- Parameters:
mapper- the mapper to define the optionals oncls- the cls the classfieldNamesare member offieldNames- the field names (names of Java fields)- Returns:
mapper
-
defineOptionals
public de.iip_ecosphere.platform.support.json.Json defineOptionals(Class<?> cls, String... fieldNames) - Specified by:
defineOptionalsin classde.iip_ecosphere.platform.support.json.Json
-
defineFields
public static com.fasterxml.jackson.databind.ObjectMapper defineFields(com.fasterxml.jackson.databind.ObjectMapper mapper, String... fieldNames) Defines a mapping of JSON names to Java field names using exactly the given names.- Parameters:
mapper- the mapper to define the optionals onfieldNames- the field names (names of JSON/Java fields)- Returns:
mapper
-
setAnnotationIntrospector
private static TestJson.OktoAnnotationIntrospector setAnnotationIntrospector(com.fasterxml.jackson.databind.ObjectMapper mapper, TestJson.OktoAnnotationIntrospector introspector, Consumer<TestJson.OktoAnnotationIntrospector> configurer) Sets the annotation introspector onmapper.- Parameters:
mapper- the mapper; the introspector is only set ifintrospectorwas null before, else the already set introspector may be reconfigured throughconfigurerintrospector- the actual introspector, may be nullconfigurer- the configurer function, may be null for none- Returns:
- the actual introspector (new if null before or reconfigured)
-
defineFields
- Specified by:
defineFieldsin classde.iip_ecosphere.platform.support.json.Json
-
exceptFields
public static TestJson.OktoAnnotationIntrospector exceptFields(com.fasterxml.jackson.databind.ObjectMapper mapper, TestJson.OktoAnnotationIntrospector introspector, String... fieldNames) Returns an object writer for a mapper that applies a filter onfieldNamesto be excluded.- Parameters:
mapper- the mapperintrospector- the current introspector, may be nullfieldNames- the field names- Returns:
- the actual introspector (new if null before or reconfigured)
-
exceptFields
- Specified by:
exceptFieldsin classde.iip_ecosphere.platform.support.json.Json
-
configureExceptFieldsFilter
public de.iip_ecosphere.platform.support.json.Json configureExceptFieldsFilter(String filterId, String... fieldNames) - Specified by:
configureExceptFieldsFilterin classde.iip_ecosphere.platform.support.json.Json
-
filterAllExceptFields
- Specified by:
filterAllExceptFieldsin classde.iip_ecosphere.platform.support.json.Json
-
convertValue
- Specified by:
convertValuein classde.iip_ecosphere.platform.support.json.Json- Throws:
IllegalArgumentException
-
failOnUnknownProperties
public de.iip_ecosphere.platform.support.json.Json failOnUnknownProperties(boolean fail) - Specified by:
failOnUnknownPropertiesin classde.iip_ecosphere.platform.support.json.Json
-
createEnumMapping
public <T> de.iip_ecosphere.platform.support.json.Json.EnumMapping<T> createEnumMapping(Class<T> type, Map<String, T> mapping) - Specified by:
createEnumMappingin classde.iip_ecosphere.platform.support.json.Json
-
declareEnums
public static com.fasterxml.jackson.databind.ObjectMapper declareEnums(com.fasterxml.jackson.databind.ObjectMapper mapper, de.iip_ecosphere.platform.support.json.Json.EnumMapping<?>... mappings) Declares enumerations on the specified mapper.- Parameters:
mapper- the mappermappings- the enumeration mappings- Returns:
mapper
-
declareEnums
public de.iip_ecosphere.platform.support.json.Json declareEnums(de.iip_ecosphere.platform.support.json.Json.EnumMapping<?>... mappings) - Specified by:
declareEnumsin classde.iip_ecosphere.platform.support.json.Json
-
configureLazy
public static TestJson.OktoAnnotationIntrospector configureLazy(com.fasterxml.jackson.databind.ObjectMapper mapper, TestJson.OktoAnnotationIntrospector introspector, Set<Object> ignore) Configures the given mapper for lazy serialization ignoring given classes and members.- Parameters:
mapper- the mapper to configureintrospector- the current introspector, may be nullignore- , classes (also as return types) and (reflection) fields that shall be ignored- Returns:
- the actual introspector (new if null before or reconfigured)
-
configureLazy
- Specified by:
configureLazyin classde.iip_ecosphere.platform.support.json.Json
-
createIterator
public static <T> de.iip_ecosphere.platform.support.json.IOIterator<T> createIterator(com.fasterxml.jackson.databind.ObjectMapper mapper, InputStream stream, Class<T> cls) throws IOException Creates an iterator over the information instreamassuming a heterogeneous collection ofcls.- Type Parameters:
T- the element type- Parameters:
mapper- the object mapper to usestream- the input stream to readcls- the element type- Returns:
- an iterator over the element types
- Throws:
IOException- if accessing the stream fails
-
createIterator
public <T> de.iip_ecosphere.platform.support.json.IOIterator<T> createIterator(InputStream stream, Class<T> cls) throws IOException - Specified by:
createIteratorin classde.iip_ecosphere.platform.support.json.Json- Throws:
IOException
-
createObjectImpl
protected de.iip_ecosphere.platform.support.json.JsonObject createObjectImpl(Reader reader) throws IOException - Specified by:
createObjectImplin classde.iip_ecosphere.platform.support.json.Json- Throws:
IOException
-
createObjectBuilderImpl
protected de.iip_ecosphere.platform.support.json.JsonObjectBuilder createObjectBuilderImpl()- Specified by:
createObjectBuilderImplin classde.iip_ecosphere.platform.support.json.Json
-
createArrayBuilderImpl
protected de.iip_ecosphere.platform.support.json.JsonArrayBuilder createArrayBuilderImpl()- Specified by:
createArrayBuilderImplin classde.iip_ecosphere.platform.support.json.Json
-
parseImpl
- Specified by:
parseImplin classde.iip_ecosphere.platform.support.json.Json
-
parseImpl
protected de.iip_ecosphere.platform.support.json.JsonIterator parseImpl(byte[] data) - Specified by:
parseImplin classde.iip_ecosphere.platform.support.json.Json
-
writeValueAsString
- Specified by:
writeValueAsStringin classde.iip_ecosphere.platform.support.json.Json- Throws:
IOException
-
createGeneratorImpl
- Specified by:
createGeneratorImplin classde.iip_ecosphere.platform.support.json.Json
-