A small library which handles reading and writing a series of JSON objects from a text file.
Available from Maven Central.
implementation 'com.autonomouslogic.jacksonobjectstream:jackson-object-stream:$version'
<dependency>
<groupId>com.autonomouslogic.jacksonobjectstream</groupId>
<artifactId>jackson-object-stream</artifactId>
<version>$version</version>
</dependency>
Objects are read from the files one by one. Any whitespace or formatting will be ignored by Jackson, so there are no special formatting requirements.
JacksonObjectStreamFactory factory = new JacksonObjectStreamFactory(new ObjectMapper());
try (JacksonObjectIterator<TestObject> iterator = factory.createReader(new File("users.json"), User.class)) {
while(iterator.hasNext()) {
User user = iterator.next();
// Use user for something.
}
}
Objects will be written to the output one by one. After each object, a newline will be inserted. Pretty printing is not supported at this time.
JacksonObjectStreamFactory factory = new JacksonObjectStreamFactory(new ObjectMapper());
try (JacksonObjectStreamWriter writer = factory.createWriter(new File("users.json"))) {
writer.writeObject(user1);
writer.writeObject(user2);
// etc.
}
Jackson does support writing/reading multiple JSON object to/from to files. This is a tiny library that simply provides the plumbing needed to do so effectively, and provides a few convenience methods at the same time.
Jackson Object Stream follows semantic versioning.
This library is licensed under the MIT-0 license.
Type | Status |
---|---|
LGTM | |
CodeClimate | |
SonarCloud | |
Libraries.io | |
Snyk | |
Codecov | |
Synatype Lift | link |