public class YamlReader extends Object
| 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.
|
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
IOExceptionpublic Object read() throws YamlException
ArrayList, HashMap, or String.YamlExceptionpublic <T> T read(Class<T> type) throws YamlException
type - The type of object to read. If null, behaves the same as {read().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().YamlExceptionprotected Object readValue(Class type, Class elementType, Class defaultType) throws YamlException, Parser.ParserException, Tokenizer.TokenizerException
protected 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 - e.g., if they
were output by another program using classes that do not exist on your classpath.ClassNotFoundExceptionprotected Object createObject(Class type) throws InvocationTargetException
InvocationTargetExceptionCopyright © 2020. All rights reserved.