Class TemplatedObjectReader
java.lang.Object
dev.enola.common.io.object.template.TemplatedObjectReader
- All Implemented Interfaces:
ObjectReader
An ObjectReader that first processes a resource as a template.
It reads a resource, parses it as a Map to be used as a model, then treats
the original resource content as a template, applies the model to it, and finally delegates
parsing of the resulting content to another ObjectReader.
This allows for self-referential templates, where values defined in a file (e.g. YAML) can be used in other parts of the same file.
NOTE: This implementation reads the entire resource into memory to perform templating. It is not suitable for very large resources.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Optional<T> optional(ReadableResource resource, Class<T> type) Read an object of Class T from the resource, if present.<T> Iterable<T> readArray(ReadableResource resource, Class<T> type) Read e.g.<T> Iterable<T> readStream(ReadableResource resource, Class<T> type) Read e.g.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.enola.common.io.object.ObjectReader
read
-
Constructor Details
-
TemplatedObjectReader
-
-
Method Details
-
optional
Description copied from interface:ObjectReaderRead an object of Class T from the resource, if present.- Specified by:
optionalin interfaceObjectReader- Throws:
IOException
-
readArray
Description copied from interface:ObjectReaderRead e.g. a JSON (or YAML) [ ... ] array.- Specified by:
readArrayin interfaceObjectReader- Throws:
IOException
-
readStream
Description copied from interface:ObjectReaderRead e.g. a YAML stream. (For formats such as plain JSON which do not directly support a streams syntax, this will always return a single element.)- Specified by:
readStreamin interfaceObjectReader- Throws:
IOException
-