public class YamlReader extends Object implements AutoCloseable
| Modifier and Type | Class and Description |
|---|---|
class |
YamlReader.YamlReaderException |
| Constructor and Description |
|---|
YamlReader(Reader reader) |
YamlReader(Reader reader,
YamlConfig config) |
YamlReader(String yaml) |
YamlReader(String yaml,
YamlConfig config) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
protected Object |
createObject(Class type)
Returns a new object of the requested type.
|
protected Class<?> |
findTagClass(String tag,
ClassLoader classLoader)
Used during reading when a tag is present, and
YamlConfig.setClassTag(String, Class) was not used for that tag. |
Object |
get(String alias)
Return the object with the given alias, or null.
|
YamlConfig |
getConfig() |
static void |
main(String[] args) |
Object |
read()
Reads the next YAML document and deserializes it into an object.
|
<T> T |
read(Class<T> type)
Reads an object of the specified type from YAML.
|
<T> T |
read(Class<T> type,
Class elementType)
Reads an array, Map, List, or Collection object of the specified type from YAML, using the specified element type.
|
<T> Iterator<T> |
readAll(Class<T> type)
Returns an iterator that reads all documents from YAML into objects.
|
protected Object |
readValue(Class type,
Class elementType,
Class defaultType)
Reads an object from the YAML.
|
public YamlReader(Reader reader)
public YamlReader(Reader reader, YamlConfig config)
public YamlReader(String yaml)
public YamlReader(String yaml, YamlConfig config)
public YamlConfig getConfig()
public Object get(String alias)
close()public void close()
throws IOException
close in interface AutoCloseableIOExceptionpublic Object read() throws YamlException
ArrayList, HashMap, or String.
This method creates and configures an instance of a class specified by the YAML data, so should be used only with YAML data from a trusted source.
YamlExceptionpublic <T> T read(Class<T> type) throws YamlException
type - The type of object to read. If null, behaves the same as {read().YamlReader.YamlReaderException - if the YAML data specifies a type that is incompatible with the specified type.YamlExceptionpublic <T> T read(Class<T> type, Class elementType) throws YamlException
type - The type of object to read. If null, behaves the same as {read().YamlReader.YamlReaderException - if the YAML data specifies a type that is incompatible with the specified type.YamlExceptionpublic <T> Iterator<T> readAll(Class<T> type)
type - The type of object to read. If null, behaves the same as {read().protected Object readValue(Class type, Class elementType, Class defaultType) throws YamlException, Parser.ParserException, Tokenizer.TokenizerException
type - May be null.YamlReader.YamlReaderException - if the YAML data specifies a type that is incompatible with the specified type.YamlExceptionParser.ParserExceptionTokenizer.TokenizerExceptionprotected Class<?> findTagClass(String tag, ClassLoader classLoader) throws ClassNotFoundException
YamlConfig.setClassTag(String, Class) was not used for that tag.
Attempts to load the class corresponding to that tag.
If this returns a non-null Class, that will be used as the deserialization type regardless of whether a type was explicitly asked for or if a default type exists.
If this returns null, no guidance will be provided by the tag and we will fall back to the default type or a requested target type, if any exist.
If this throws a ClassNotFoundException, parsing will fail.
The default implementation is simply Class.forName(tag, true, classLoader);
and never returns null.
You can override this to handle cases where you do not want to respect the type tags found in a document, eg if they were output by another program using classes that do not exist on your classpath.
ClassNotFoundExceptionprotected Object createObject(Class type) throws InvocationTargetException
InvocationTargetExceptionCopyright © 2023. All rights reserved.