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
+29-2
Original file line number
Diff line number
Diff line change
@@ -172,10 +172,37 @@ As convenient as data-binding (to/from POJOs) can be; and as flexible as Tree mo
172
172
It is the underlying processing model that data-binding and Tree Model both build upon, but it is also exposed to users who want ultimate performance and/or control over parsing or generation details.
173
173
174
174
For in-depth explanation, look at [Jackson Core component](https://github.com/FasterXML/jackson-core).
175
-
But let's look at a simple teaser to whet your appetite:
175
+
But let's look at a simple teaser to whet your appetite.
176
176
177
-
(TO BE COMPLETED)
177
+
```java
178
+
JsonFactory f = mapper.getFactory(); // may alternatively construct directly too
179
+
180
+
// First: write simple JSON output
181
+
File jsonFile =newJsonFile("test.json");
182
+
JsonGenerator g = f.createGenerator(jsonFile);
183
+
// write JSON: { "message" : "Hello world!" }
184
+
g.writeStartObject();
185
+
g.writeStringField("message", "Hello world!");
186
+
g.writeEndObject();
187
+
g.close();
188
+
189
+
// Second: read file back
190
+
JsonParser p = f.createParser(jsonFile);
191
+
192
+
JsonToken t = p.nextToken(); // Should be JsonToken.START_OBJECT
193
+
t = p.nextToken(); // JsonToken.FIELD_NAME
194
+
if ((t !=JsonToken.FIELD_NAME) ||!"message".equals(p.getCurrentName())) {
195
+
// handle error
196
+
}
197
+
t = p.nextToken();
198
+
if (t !=JsonToken.VALUE_STRING) {
199
+
// similarly
200
+
}
201
+
String msg = p.getText();
202
+
System.out.printf("My message to you is: %s!\n", msg);
0 commit comments