@@ -22,31 +22,61 @@ To use this extension on Maven-based projects, use following dependency:
22
22
<dependency >
23
23
<groupId >com.fasterxml.jackson.dataformat</groupId >
24
24
<artifactId >jackson-dataformat-yaml</artifactId >
25
- <version >2.8.3 </version >
25
+ <version >2.13.4 </version >
26
26
</dependency >
27
27
```
28
28
29
29
# Usage
30
30
31
31
## Simple usage
32
32
33
- Usage is as with basic ` JsonFactory ` ; most commonly you will just construct a standard ` ObjectMapper ` with ` com.fasterxml.jackson.dataformat.yaml.YAMLFactory ` , like so :
33
+ Usage is through basic ` JsonFactory ` and/or ` ObjectMapper ` API but you will construct instances differently :
34
34
35
35
``` java
36
- ObjectMapper mapper = new ObjectMapper (new YAMLFactory ());
36
+ // Mapper with default configuration
37
+ ObjectMapper mapper = new YAMLMapper ();
37
38
User user = mapper. readValue(yamlSource, User . class);
39
+
40
+ // Or using builder
41
+ ObjectMapper mapper = YAMLMapper . builder()
42
+ .disable(YAMLGenerator . Feature . WRITE_DOC_START_MARKER )
43
+ .build();
44
+ Json
45
+
38
46
```
39
47
40
48
but you can also just use underlying ` YAMLFactory ` and parser it produces, for event-based processing:
41
49
42
50
``` java
43
51
YAMLFactory factory = new YAMLFactory ();
44
- JsonParser parser = factory. createJsonParser (yamlString); // don't be fooled by method name...
52
+ JsonParser parser = factory. createParser (yamlString); // don't be fooled by method name...
45
53
while (parser. nextToken() != null ) {
46
54
// do something!
47
55
}
48
56
```
49
57
58
+ ## Configuration
59
+
60
+ Most configuration is applied during mapper instance configuration, through
61
+ ` YAMLMapper.Builder ` , similar to how JSON-based plain ` ObjectMapper ` is configured.
62
+
63
+ ## Known problems
64
+
65
+ ### Maximum input YAML document size (3 MB)
66
+
67
+ SnakeYAML implementation starts imposing the default limit of 3 megabyte document
68
+ size as of version 1.32, used by Jackson 2.14.0. If you hit this limitation,
69
+ you need to explicitly increase the limit by configuring ` YAMLFactory ` and constructing ` YAMLMapper ` with that:
70
+
71
+ ``` java
72
+ LoaderOptions loaderOptions = new LoaderOptions ();
73
+ loaderOptions. setCodePointLimit(10 * 1024 * 1024 ); // 10 MB
74
+ YAMLFactory yamlFactory = YAMLFactory . builder()
75
+ .loaderOptions(loaderOptions)
76
+ .build();
77
+ YAMLMapper mapper = new YAMLMapper (yamlFactory);
78
+ ```
79
+
50
80
# Documentation
51
81
52
82
* [ Wiki] ( ../../../wiki ) contains links to Javadocs, external documentation
0 commit comments