Class DataMapper
java.lang.Object
de.iip_ecosphere.platform.services.environment.DataMapper
Maps data from a stream to input instances for a service. This class is intended as a basis for testing (here
avoiding the test scope for generated code). The idea is that all input types are represented as attributes of a
generated class (given in terms of a JSON file/stream). The generated service test calls this class providing a
consumer to take over the data.
As we read JSON through Jackson, currently the fields must comply with camel case Java naming convention
irrespective how the fields are written in the generated Java class.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBase class to represent all potential inputs to the service and the JSON input format.static interfaceInterface to represent all potential inputs to the service and the JSON input format.static classExtendedDataMapper.MappingConsumerto takeDataMapper.BaseDataUnit.$periodandDataMapper.BaseDataUnit.$repeatsinto account.private static classImplements a mapper entry forMappingConsumer.static classProvides a default consumer implementation formapJsonData(InputStream, Class, Consumer)which maps attribute values to registered consumers. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Class<? extends T> createBaseDataUnitClass(Class<T> cls) Creates a dynamic class extendingclsand implementingDataMapper.BaseDataUnitFunctions.static <T> voidmapJsonData(InputStream stream, Class<T> cls, Consumer<T> cons) Maps the data instreamto instances ofcls, one instance per line.static <T> voidmapJsonData(InputStream stream, Class<T> cls, Consumer<T> cons, boolean failOnUnknownProperties) Maps the data instreamto instances ofcls, one instance per line.static <T> voidmapJsonData(InputStream stream, Class<T> cls, Consumer<T> cons, boolean failOnUnknownProperties, Supplier<Boolean> continueFunction) Maps the data instreamto instances ofcls, one instance per line.static <T> de.iip_ecosphere.platform.support.json.IOIterator<T> mapJsonDataToIterator(InputStream stream, Class<T> cls) Maps the data instreamto instances ofcls, one instance per line, returned in terms of an iterator.static <T> de.iip_ecosphere.platform.support.json.IOIterator<T> mapJsonDataToIterator(InputStream stream, Class<T> cls, boolean failOnUnknownProperties) Maps the data instreamto instances ofcls, one instance per line, returned in terms of an iterator.
-
Constructor Details
-
DataMapper
public DataMapper()
-
-
Method Details
-
createBaseDataUnitClass
Creates a dynamic class extendingclsand implementingDataMapper.BaseDataUnitFunctions.- Type Parameters:
T- the type of the class- Parameters:
cls- the class to extend (assuming it'S a generated data class)- Returns:
- the created class
-
mapJsonData
public static <T> void mapJsonData(InputStream stream, Class<T> cls, Consumer<T> cons) throws IOException Maps the data instreamto instances ofcls, one instance per line. Callsconsper instance/line. Closesstream. Ignores unknown attributes incls.- Type Parameters:
T- the type of data to read- Parameters:
stream- the stream to read (may be null for none)cls- the type of data to readcons- the consumer to be called per instance- Throws:
IOException- if I/O or JSON parsing errors occur
-
mapJsonData
public static <T> void mapJsonData(InputStream stream, Class<T> cls, Consumer<T> cons, boolean failOnUnknownProperties) throws IOException Maps the data instreamto instances ofcls, one instance per line. Callsconsper instance/line. Closesstream.- Type Parameters:
T- the type of data to read- Parameters:
stream- the stream to read (may be null for none)cls- the type of data to readcons- the consumer to be called per instancefailOnUnknownProperties- whether parsing shall be tolerant or not, the latter may be helpful for debugging- Throws:
IOException- if I/O or JSON parsing errors occur
-
mapJsonData
public static <T> void mapJsonData(InputStream stream, Class<T> cls, Consumer<T> cons, boolean failOnUnknownProperties, Supplier<Boolean> continueFunction) throws IOException Maps the data instreamto instances ofcls, one instance per line. Callsconsper instance/line. Closesstream.- Type Parameters:
T- the type of data to read- Parameters:
stream- the stream to read (may be null for none)cls- the type of data to readcons- the consumer to be called per instancefailOnUnknownProperties- whether parsing shall be tolerant or not, the latter may be helpful for debuggingcontinueFunction- optional function that tells the data mapper to go on reading the input, may be null for none- Throws:
IOException- if I/O or JSON parsing errors occur
-
mapJsonDataToIterator
public static <T> de.iip_ecosphere.platform.support.json.IOIterator<T> mapJsonDataToIterator(InputStream stream, Class<T> cls) throws IOException Maps the data instreamto instances ofcls, one instance per line, returned in terms of an iterator. Ignores unknown attributes incls.- Type Parameters:
T- the type of data to read- Parameters:
stream- the stream to read (may be null for none)cls- the type of data to read- Returns:
- the data iterator
- Throws:
IOException- if I/O or JSON parsing errors occur
-
mapJsonDataToIterator
public static <T> de.iip_ecosphere.platform.support.json.IOIterator<T> mapJsonDataToIterator(InputStream stream, Class<T> cls, boolean failOnUnknownProperties) throws IOException Maps the data instreamto instances ofcls, one instance per line, returned in terms of an iterator. Ignores unknown attributes incls.- Type Parameters:
T- the type of data to read- Parameters:
stream- the stream to read (may be null for none)cls- the type of data to readfailOnUnknownProperties- whether parsing shall be tolerant or not, the latter may be helpful for debugging- Returns:
- the data iterator
- Throws:
IOException- if I/O or JSON parsing errors occur
-