You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
## Overview
2
2
3
-
!YamlBeans makes it easy to serialize and deserialize Java object graphs to and from YAML, a human-friendly data format. Replace XML and properties files with YAML for more expressive power (lists, maps, anchors, etc) and easier hand-editing.
3
+
YamlBeans makes it easy to serialize and deserialize Java object graphs to and from YAML, a human-friendly data format. Replace XML and properties files with YAML for more expressive power (lists, maps, anchors, etc) and easier hand-editing.
The !YamlReader class is used to deserialize YAML to Java objects. The following YAML defines a Map with four entries. The "phone numbers" entry is a List of two items, each of which is a Map.
10
+
The YamlReader class is used to deserialize YAML to Java objects. The following YAML defines a Map with four entries. The "phone numbers" entry is a List of two items, each of which is a Map.
11
11
12
12
```yaml
13
13
name: Nathan Sweet
@@ -20,7 +20,7 @@ The !YamlReader class is used to deserialize YAML to Java objects. The following
20
20
number: 425-555-2306
21
21
```
22
22
23
-
The "read" method reads the next YAML document and deserializes it into !HashMaps, !ArrayLists, and Strings. Since we know the root object defined in the YAML of our example is a Map, we can cast the object and make use of it.
23
+
The "read" method reads the next YAML document and deserializes it into HashMaps, ArrayLists, and Strings. Since we know the root object defined in the YAML of our example is a Map, we can cast the object and make use of it.
24
24
25
25
```java
26
26
YamlReader reader = new YamlReader(new FileReader("contact.yml"));
@@ -32,7 +32,7 @@ The "read" method reads the next YAML document and deserializes it into !HashMap
32
32
33
33
## Multiple objects
34
34
35
-
A stream of YAML can contain more than one YAML document. Each call to !YamlReader#read() deserializes the next document into an object. YAML documents are delimited by "---" (this is optional for the first document).
35
+
A stream of YAML can contain more than one YAML document. Each call to YamlReader#read() deserializes the next document into an object. YAML documents are delimited by "---" (this is optional for the first document).
36
36
37
37
```yaml
38
38
name: Nathan Sweet
@@ -55,7 +55,7 @@ This prints the String "28" then "25":
55
55
56
56
## Deserializing other classes
57
57
58
-
There are two ways to deserialize something other than !HashMaps, !ArrayLists, and Strings. Imagine this YAML document and Java class:
58
+
There are two ways to deserialize something other than HashMaps, ArrayLists, and Strings. Imagine this YAML document and Java class:
59
59
60
60
```yaml
61
61
name: Nathan Sweet
@@ -68,17 +68,17 @@ There are two ways to deserialize something other than !HashMaps, !ArrayLists, a
68
68
}
69
69
```
70
70
71
-
The "read" method can be passed a class, so the !YamlReader knows what it is deserializing:
71
+
The "read" method can be passed a class, so the YamlReader knows what it is deserializing:
The !YamlReader creates an instance of the Contact class and sets the "name" and "age" fields. The !YamlReader determines the "age" value in the YAML needs to be converted into a int. Deserialization would have failed if the age was not a valid int. The !YamlReader can set public fields and bean setter methods.
79
+
The YamlReader creates an instance of the Contact class and sets the "name" and "age" fields. The YamlReader determines the "age" value in the YAML needs to be converted into a int. Deserialization would have failed if the age was not a valid int. The YamlReader can set public fields and bean setter methods.
80
80
81
-
Instead of telling the !YamlReader what type to deserialize, the type can alternatively be specified in the YAML using a tag:
81
+
Instead of telling the YamlReader what type to deserialize, the type can alternatively be specified in the YAML using a tag:
82
82
83
83
```yaml
84
84
!com.example.Contact
@@ -88,7 +88,7 @@ Instead of telling the !YamlReader what type to deserialize, the type can altern
88
88
89
89
## Serializing objects
90
90
91
-
The !YamlWriter class is used to serialize Java objects to YAML. The "write" method automatically handles this by recognizing public fields and bean getter methods.
91
+
The YamlWriter class is used to serialize Java objects to YAML. The "write" method automatically handles this by recognizing public fields and bean getter methods.
92
92
93
93
```java
94
94
Contact contact = new Contact();
@@ -107,7 +107,7 @@ This outputs:
107
107
age: 28
108
108
```
109
109
110
-
The tags are automatically output as needed so that the !YamlReader class will be able to reconstruct the object graph. For example, serializing this !ArrayList does not output any tag for the list because !YamlReader uses an !ArrayList by default.
110
+
The tags are automatically output as needed so that the YamlReader class will be able to reconstruct the object graph. For example, serializing this ArrayList does not output any tag for the list because YamlReader uses an ArrayList by default.
111
111
112
112
```java
113
113
List list = new ArrayList();
@@ -119,7 +119,7 @@ The tags are automatically output as needed so that the !YamlReader class will b
119
119
- cow
120
120
```
121
121
122
-
If the list was a !LinkedList, then !YamlWriter knows that a tag is needed and outputs:
122
+
If the list was a LinkedList, then YamlWriter knows that a tag is needed and outputs:
123
123
124
124
```java
125
125
List list = new LinkedList();
@@ -132,11 +132,11 @@ If the list was a !LinkedList, then !YamlWriter knows that a tag is needed and o
132
132
- cow
133
133
```
134
134
135
-
Note that it is not advisable to subclass Collection or Map. !YamlBeans will only serialize the collection or map and its elements, not any additional fields.
135
+
Note that it is not advisable to subclass Collection or Map. YamlBeans will only serialize the collection or map and its elements, not any additional fields.
136
136
137
137
## Complex graphs
138
138
139
-
!YamlBeans can serialize any object graph.
139
+
YamlBeans can serialize any object graph.
140
140
141
141
```java
142
142
public class Contact {
@@ -200,7 +200,7 @@ The output no longer contains the full classname for the Contact class.
200
200
201
201
## Lists and maps
202
202
203
-
When reading or writing a List or Map, !YamlBeans cannot know what type of objects are supposed to be in the List or Map, so it will write out a tag.
203
+
When reading or writing a List or Map, YamlBeans cannot know what type of objects are supposed to be in the List or Map, so it will write out a tag.
204
204
205
205
```yaml
206
206
!com.example.Contact
@@ -223,7 +223,7 @@ This can make the YAML less readable. To improve this, you may define what eleme
223
223
writer.close();
224
224
```
225
225
226
-
Now !YamlBeans knows what to expect for elements of the "phoneNumbers" field, so extra tags will not be output.
226
+
Now YamlBeans knows what to expect for elements of the "phoneNumbers" field, so extra tags will not be output.
227
227
228
228
```yaml
229
229
!com.example.Contact
@@ -234,7 +234,7 @@ Now !YamlBeans knows what to expect for elements of the "phoneNumbers" field, so
234
234
- number: 206-555-7654
235
235
```
236
236
237
-
Setting the element type for a Map field tells !YamlBeans what to expect for values in the Map. Keys in a Map are always Strings.
237
+
Setting the element type for a Map field tells YamlBeans what to expect for values in the Map. Keys in a Map are always Strings.
238
238
239
239
## Anchors
240
240
@@ -248,7 +248,7 @@ When an object graph contains multiple references to the same object, an anchor
248
248
best friend: *1
249
249
```
250
250
251
-
In this map, the "oldest friend" and "best friend" keys reference the same object. The !YamlReader automatically handles the anchors in the YAML when rebuilding the object graph. By default, the !YamlWriter automatically outputs anchors when writing objects.
251
+
In this map, the "oldest friend" and "best friend" keys reference the same object. The YamlReader automatically handles the anchors in the YAML when rebuilding the object graph. By default, the YamlWriter automatically outputs anchors when writing objects.
252
252
253
253
```java
254
254
Contact contact = new Contact();
@@ -261,10 +261,10 @@ In this map, the "oldest friend" and "best friend" keys reference the same objec
261
261
262
262
## Architecture
263
263
264
-
The YAML tokenizer, parser, and emitter are based on those from the JvYAML project. They have been heavily refactored, bugs fixed, etc. The rest of the JvYAML project was not used because of its complexity. !YamlBeans strives for the simplest possible thing that works, with the goal being to make it easy to use the YAML data format with Java.
264
+
The YAML tokenizer, parser, and emitter are based on those from the JvYAML project. They have been heavily refactored, bugs fixed, etc. The rest of the JvYAML project was not used because of its complexity. YamlBeans strives for the simplest possible thing that works, with the goal being to make it easy to use the YAML data format with Java.
265
265
266
-
!YamlBeans supports YAML version 1.0 and 1.1.
266
+
YamlBeans supports YAML version 1.0 and 1.1.
267
267
268
268
## More info
269
269
270
-
See the javadocs for various other features available on the !YamlConfig class.
270
+
See the javadocs for various other features available on the YamlConfig class.
0 commit comments