Skip to content

Commit 595c895

Browse files
committed
update README regarding streaming api
1 parent 2e0453f commit 595c895

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

README.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,37 @@ As convenient as data-binding (to/from POJOs) can be; and as flexible as Tree mo
172172
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.
173173

174174
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.
176176

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 = new JsonFile("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);
203+
p.close();
178204

205+
```
179206

180207
## 10 minute tutorial: configuration
181208

0 commit comments

Comments
 (0)