public class Yaml
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Yaml.EventIterable |
private static class |
Yaml.NodeIterable |
private static class |
Yaml.SilentEmitter |
private static class |
Yaml.YamlIterable |
Modifier and Type | Field and Description |
---|---|
protected BaseConstructor |
constructor |
protected DumperOptions |
dumperOptions |
protected LoaderOptions |
loadingConfig |
private java.lang.String |
name |
protected Representer |
representer |
protected Resolver |
resolver |
Constructor and Description |
---|
Yaml()
Create Yaml instance.
|
Yaml(BaseConstructor constructor)
Create Yaml instance.
|
Yaml(BaseConstructor constructor,
Representer representer)
Create Yaml instance.
|
Yaml(BaseConstructor constructor,
Representer representer,
DumperOptions dumperOptions)
Create Yaml instance.
|
Yaml(BaseConstructor constructor,
Representer representer,
DumperOptions dumperOptions,
LoaderOptions loadingConfig)
Create Yaml instance.
|
Yaml(BaseConstructor constructor,
Representer representer,
DumperOptions dumperOptions,
LoaderOptions loadingConfig,
Resolver resolver)
Create Yaml instance.
|
Yaml(BaseConstructor constructor,
Representer representer,
DumperOptions dumperOptions,
Resolver resolver)
Create Yaml instance.
|
Yaml(DumperOptions dumperOptions)
Create Yaml instance.
|
Yaml(LoaderOptions loadingConfig)
Create Yaml instance.
|
Yaml(Representer representer)
Create Yaml instance.
|
Yaml(Representer representer,
DumperOptions dumperOptions)
Create Yaml instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addImplicitResolver(Tag tag,
java.util.regex.Pattern regexp,
java.lang.String first)
Add an implicit scalar detector.
|
void |
addImplicitResolver(Tag tag,
java.util.regex.Pattern regexp,
java.lang.String first,
int limit)
Add an implicit scalar detector.
|
void |
addTypeDescription(TypeDescription td) |
Node |
compose(java.io.Reader yaml)
Parse the first YAML document in a stream and produce the corresponding representation tree.
|
java.lang.Iterable<Node> |
composeAll(java.io.Reader yaml)
Parse all YAML documents in a stream and produce corresponding representation trees.
|
java.lang.String |
dump(java.lang.Object data)
Serialize a Java object into a YAML String.
|
void |
dump(java.lang.Object data,
java.io.Writer output)
Serialize a Java object into a YAML stream.
|
java.lang.String |
dumpAll(java.util.Iterator<? extends java.lang.Object> data)
Serialize a sequence of Java objects into a YAML String.
|
void |
dumpAll(java.util.Iterator<? extends java.lang.Object> data,
java.io.Writer output)
Serialize a sequence of Java objects into a YAML stream.
|
private void |
dumpAll(java.util.Iterator<? extends java.lang.Object> data,
java.io.Writer output,
Tag rootTag) |
java.lang.String |
dumpAs(java.lang.Object data,
Tag rootTag,
DumperOptions.FlowStyle flowStyle)
Serialize a Java object into a YAML string.
|
java.lang.String |
dumpAsMap(java.lang.Object data)
Serialize a Java object into a YAML string.
|
java.lang.String |
getName()
Get a meaningful name.
|
private static DumperOptions |
initDumperOptions(Representer representer) |
<T> T |
load(java.io.InputStream io)
Parse the only YAML document in a stream and produce the corresponding Java object.
|
<T> T |
load(java.io.Reader io)
Parse the only YAML document in a stream and produce the corresponding Java object.
|
<T> T |
load(java.lang.String yaml)
Parse the only YAML document in a String and produce the corresponding Java object.
|
java.lang.Iterable<java.lang.Object> |
loadAll(java.io.InputStream yaml)
Parse all YAML documents in a stream and produce corresponding Java objects.
|
java.lang.Iterable<java.lang.Object> |
loadAll(java.io.Reader yaml)
Parse all YAML documents in the Reader and produce corresponding Java objects.
|
java.lang.Iterable<java.lang.Object> |
loadAll(java.lang.String yaml)
Parse all YAML documents in a String and produce corresponding Java objects.
|
<T> T |
loadAs(java.io.InputStream input,
java.lang.Class<T> type)
Parse the only YAML document in a stream and produce the corresponding Java object.
|
<T> T |
loadAs(java.io.Reader io,
java.lang.Class<T> type)
Parse the only YAML document in a stream and produce the corresponding Java object.
|
<T> T |
loadAs(java.lang.String yaml,
java.lang.Class<T> type)
Parse the only YAML document in a String and produce the corresponding Java object.
|
private java.lang.Object |
loadFromReader(StreamReader sreader,
java.lang.Class<?> type) |
java.lang.Iterable<Event> |
parse(java.io.Reader yaml)
Parse a YAML stream and produce parsing events.
|
Node |
represent(java.lang.Object data)
Produce the corresponding representation tree for a given Object.
|
java.util.List<Event> |
serialize(Node data)
Serialize the representation tree into Events.
|
void |
serialize(Node node,
java.io.Writer output)
Serialize (dump) a YAML node into a YAML stream.
|
void |
setBeanAccess(BeanAccess beanAccess) |
void |
setName(java.lang.String name)
Set a meaningful name to be shown in toString()
|
java.lang.String |
toString() |
protected final Resolver resolver
private java.lang.String name
protected BaseConstructor constructor
protected Representer representer
protected DumperOptions dumperOptions
protected LoaderOptions loadingConfig
public Yaml()
public Yaml(DumperOptions dumperOptions)
dumperOptions
- DumperOptions to configure outgoing objectspublic Yaml(LoaderOptions loadingConfig)
loadingConfig
- LoadingConfig to control load behaviorpublic Yaml(Representer representer)
representer
- Representer to emit outgoing objectspublic Yaml(BaseConstructor constructor)
constructor
- BaseConstructor to construct incoming documentspublic Yaml(BaseConstructor constructor, Representer representer)
constructor
- BaseConstructor to construct incoming documentsrepresenter
- Representer to emit outgoing objectspublic Yaml(Representer representer, DumperOptions dumperOptions)
representer
- Representer to emit outgoing objectsdumperOptions
- DumperOptions to configure outgoing objectspublic Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions)
constructor
- BaseConstructor to construct incoming documentsrepresenter
- Representer to emit outgoing objectsdumperOptions
- DumperOptions to configure outgoing objectspublic Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions, LoaderOptions loadingConfig)
constructor
- BaseConstructor to construct incoming documentsrepresenter
- Representer to emit outgoing objectsdumperOptions
- DumperOptions to configure outgoing objectsloadingConfig
- LoadingConfig to control load behaviorpublic Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions, Resolver resolver)
constructor
- BaseConstructor to construct incoming documentsrepresenter
- Representer to emit outgoing objectsdumperOptions
- DumperOptions to configure outgoing objectsresolver
- Resolver to detect implicit typepublic Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions, LoaderOptions loadingConfig, Resolver resolver)
constructor
- BaseConstructor to construct incoming documentsrepresenter
- Representer to emit outgoing objectsdumperOptions
- DumperOptions to configure outgoing objectsloadingConfig
- LoadingConfig to control load behaviorresolver
- Resolver to detect implicit typeprivate static DumperOptions initDumperOptions(Representer representer)
public java.lang.String dump(java.lang.Object data)
data
- Java object to be Serialized to YAMLpublic Node represent(java.lang.Object data)
data
- instance to build the representation tree forpublic java.lang.String dumpAll(java.util.Iterator<? extends java.lang.Object> data)
data
- Iterator with Objectspublic void dump(java.lang.Object data, java.io.Writer output)
data
- Java object to be serialized to YAMLoutput
- stream to write topublic void dumpAll(java.util.Iterator<? extends java.lang.Object> data, java.io.Writer output)
data
- Iterator with Objectsoutput
- stream to write toprivate void dumpAll(java.util.Iterator<? extends java.lang.Object> data, java.io.Writer output, Tag rootTag)
public java.lang.String dumpAs(java.lang.Object data, Tag rootTag, DumperOptions.FlowStyle flowStyle)
Serialize a Java object into a YAML string. Override the default root tag with
rootTag
.
This method is similar to Yaml.dump(data)
except that the root tag for the whole
document is replaced with the given tag. This has two main uses.
First, if the root tag is replaced with a standard YAML tag, such as Tag.MAP
, then
the object will be dumped as a map. The root tag will appear as !!map
, or blank
(implicit !!map).
Second, if the root tag is replaced by a different custom tag, then the document appears to be a different type when loaded. For example, if an instance of MyClass is dumped with the tag !!YourClass, then it will be handled as an instance of YourClass when loaded.
data
- Java object to be serialized to YAMLrootTag
- the tag for the whole YAML document. The tag should be Tag.MAP for a JavaBean to
make the tag disappear (to use implicit tag !!map). If null
is provided
then the standard tag with the full class name is used.flowStyle
- flow style for the whole document. See Chapter 10. Collection Styles
http://yaml.org/spec/1.1/#id930798. If null
is provided then the flow style
from DumperOptions is used.public java.lang.String dumpAsMap(java.lang.Object data)
Serialize a Java object into a YAML string. Override the default root tag with
Tag.MAP
.
This method is similar to Yaml.dump(data)
except that the root tag for the whole
document is replaced with Tag.MAP
tag (implicit !!map).
Block Mapping is used as the collection style. See 10.2.2. Block Mappings (http://yaml.org/spec/1.1/#id934537)
data
- Java object to be serialized to YAMLpublic void serialize(Node node, java.io.Writer output)
node
- YAML node to be serialized to YAMLoutput
- stream to write topublic java.util.List<Event> serialize(Node data)
data
- representation treepublic <T> T load(java.lang.String yaml)
T
- the class of the instance to be createdyaml
- YAML data to load from (BOM must not be present)public <T> T load(java.io.InputStream io)
T
- the class of the instance to be createdio
- data to load from (BOM is respected to detect encoding and removed from the data)public <T> T load(java.io.Reader io)
T
- the class of the instance to be createdio
- data to load from (BOM must not be present)public <T> T loadAs(java.io.Reader io, java.lang.Class<T> type)
T
- Class is defined by the second argumentio
- data to load from (BOM must not be present)type
- Class of the object to be createdpublic <T> T loadAs(java.lang.String yaml, java.lang.Class<T> type)
T
- Class is defined by the second argumentyaml
- YAML data to load from (BOM must not be present)type
- Class of the object to be createdpublic <T> T loadAs(java.io.InputStream input, java.lang.Class<T> type)
T
- Class is defined by the second argumentinput
- data to load from (BOM is respected to detect encoding and removed from the data)type
- Class of the object to be createdprivate java.lang.Object loadFromReader(StreamReader sreader, java.lang.Class<?> type)
public java.lang.Iterable<java.lang.Object> loadAll(java.io.Reader yaml)
yaml
- YAML data to load from (BOM must not be present)public java.lang.Iterable<java.lang.Object> loadAll(java.lang.String yaml)
yaml
- YAML data to load from (BOM must not be present)public java.lang.Iterable<java.lang.Object> loadAll(java.io.InputStream yaml)
yaml
- YAML data to load from (BOM is respected to detect encoding and removed from the
data)public Node compose(java.io.Reader yaml)
yaml
- YAML documentpublic java.lang.Iterable<Node> composeAll(java.io.Reader yaml)
yaml
- stream of YAML documentspublic void addImplicitResolver(Tag tag, java.util.regex.Pattern regexp, java.lang.String first)
tag
- tag to assign to the noderegexp
- regular expression to match againstfirst
- a sequence of possible initial characters or null (which means any).public void addImplicitResolver(Tag tag, java.util.regex.Pattern regexp, java.lang.String first, int limit)
tag
- tag to assign to the noderegexp
- regular expression to match againstfirst
- a sequence of possible initial characters or null (which means any).limit
- the max length of the value which may match the regular expressionpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getName()
public void setName(java.lang.String name)
name
- human readable namepublic java.lang.Iterable<Event> parse(java.io.Reader yaml)
yaml
- YAML document(s)public void setBeanAccess(BeanAccess beanAccess)
public void addTypeDescription(TypeDescription td)