Class DataMapper
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.DataMapper
-
public class DataMapper extends java.lang.ObjectMaps 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.- Author:
- Holger Eichelberger, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataMapper.BaseDataUnitBase class to represent all potential inputs to the service and the JSON input format.static classDataMapper.BaseMappingConsumer<B extends DataMapper.BaseDataUnit>ExtendedDataMapper.MappingConsumerto takeDataMapper.BaseDataUnit.$periodandDataMapper.BaseDataUnit.$repeatsinto account.static interfaceDataMapper.IOIterator<T>An iterator that can throwIOException.private static classDataMapper.MapperEntry<T>Implements a mapper entry forMappingConsumer.static classDataMapper.MappingConsumer<T>Provides a default consumer implementation formapJsonData(InputStream, Class, Consumer)which maps attribute values to registered consumers.
-
Constructor Summary
Constructors Constructor Description DataMapper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> voidmapJsonData(java.io.InputStream stream, java.lang.Class<T> cls, java.util.function.Consumer<T> cons)Maps the data instreamto instances ofcls, one instance per line.static <T> voidmapJsonData(java.io.InputStream stream, java.lang.Class<T> cls, java.util.function.Consumer<T> cons, boolean failOnUnknownProperties)Maps the data instreamto instances ofcls, one instance per line.static <T> voidmapJsonData(java.io.InputStream stream, java.lang.Class<T> cls, java.util.function.Consumer<T> cons, boolean failOnUnknownProperties, java.util.function.Supplier<java.lang.Boolean> continueFunction)Maps the data instreamto instances ofcls, one instance per line.static <T> DataMapper.IOIterator<T>mapJsonDataToIterator(java.io.InputStream stream, java.lang.Class<T> cls)Maps the data instreamto instances ofcls, one instance per line, returned in terms of an iterator.static <T> DataMapper.IOIterator<T>mapJsonDataToIterator(java.io.InputStream stream, java.lang.Class<T> cls, boolean failOnUnknownProperties)Maps the data instreamto instances ofcls, one instance per line, returned in terms of an iterator.
-
-
-
Method Detail
-
mapJsonData
public static <T> void mapJsonData(java.io.InputStream stream, java.lang.Class<T> cls, java.util.function.Consumer<T> cons) throws java.io.IOExceptionMaps 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:
java.io.IOException- if I/O or JSON parsing errors occur
-
mapJsonData
public static <T> void mapJsonData(java.io.InputStream stream, java.lang.Class<T> cls, java.util.function.Consumer<T> cons, boolean failOnUnknownProperties) throws java.io.IOExceptionMaps 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:
java.io.IOException- if I/O or JSON parsing errors occur
-
mapJsonData
public static <T> void mapJsonData(java.io.InputStream stream, java.lang.Class<T> cls, java.util.function.Consumer<T> cons, boolean failOnUnknownProperties, java.util.function.Supplier<java.lang.Boolean> continueFunction) throws java.io.IOExceptionMaps 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:
java.io.IOException- if I/O or JSON parsing errors occur
-
mapJsonDataToIterator
public static <T> DataMapper.IOIterator<T> mapJsonDataToIterator(java.io.InputStream stream, java.lang.Class<T> cls) throws java.io.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:
java.io.IOException- if I/O or JSON parsing errors occur
-
mapJsonDataToIterator
public static <T> DataMapper.IOIterator<T> mapJsonDataToIterator(java.io.InputStream stream, java.lang.Class<T> cls, boolean failOnUnknownProperties) throws java.io.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:
java.io.IOException- if I/O or JSON parsing errors occur
-
-