io.setl.json.io.SafeGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of canonical-json Show documentation
Show all versions of canonical-json Show documentation
An implementation of the Canonical JSON format with support for javax.json and Jackson
The newest version!
package io.setl.json.io;
import io.setl.json.Canonical;
/**
* The safe generator builds a copy of the structure and then passes it to a trusted generator.
*
* @author Simon Greatrix on 27/01/2020.
*/
class SafeGenerator extends InMemoryGenerator {
private final TrustedGenerator target;
SafeGenerator(Formatter formatter) {
target = new TrustedGenerator(formatter);
}
@Override
public void close() {
try {
super.close();
} finally {
target.close();
}
}
protected void closeWith(Canonical canonical) {
if (canonical != null) {
target.write(canonical);
}
}
@Override
public void flush() {
// This is pretty much always a no-op, unless you want to flush anything written to the output prior to starting the generator. During generation nothing
// is written as it is prepared in-memory.
if (isInRoot()) {
target.flush();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy