/**
* This implementation will create JSON output as output stream.
*
+ * <p>
* Values of leaf and leaf-list are NOT translated according to codecs.
- *
*/
public final class JSONNormalizedNodeStreamWriter implements NormalizedNodeStreamWriter {
/**
private final JsonWriter writer;
private JSONStreamWriterContext context;
- private JSONNormalizedNodeStreamWriter(final JSONCodecFactory codecFactory, final SchemaPath path, final JsonWriter JsonWriter, final JSONStreamWriterRootContext rootContext) {
- this.writer = Preconditions.checkNotNull(JsonWriter);
+ private JSONNormalizedNodeStreamWriter(final JSONCodecFactory codecFactory, final SchemaPath path,
+ final JsonWriter writer, final JSONStreamWriterRootContext rootContext) {
+ this.writer = Preconditions.checkNotNull(writer);
this.codecs = Preconditions.checkNotNull(codecFactory);
this.tracker = SchemaTracker.create(codecFactory.getSchemaContext(), path);
this.context = Preconditions.checkNotNull(rootContext);
/**
* Create a new stream writer, which writes to the specified output stream.
*
+ * <p>
* The codec factory can be reused between multiple writers.
*
+ * <p>
* Returned writer is exclusive user of JsonWriter, which means it will start
* top-level JSON element and ends it.
*
+ * <p>
* This instance of writer can be used only to emit one top level element,
* otherwise it will produce incorrect JSON.
*
* @param jsonWriter JsonWriter
* @return A stream writer instance
*/
- public static NormalizedNodeStreamWriter createExclusiveWriter(final JSONCodecFactory codecFactory, final SchemaPath path, final URI initialNs, final JsonWriter jsonWriter) {
- return new JSONNormalizedNodeStreamWriter(codecFactory, path, jsonWriter, new JSONStreamWriterExclusiveRootContext(initialNs));
+ public static NormalizedNodeStreamWriter createExclusiveWriter(final JSONCodecFactory codecFactory,
+ final SchemaPath path, final URI initialNs, final JsonWriter jsonWriter) {
+ return new JSONNormalizedNodeStreamWriter(codecFactory, path, jsonWriter,
+ new JSONStreamWriterExclusiveRootContext(initialNs));
}
/**
* Create a new stream writer, which writes to the specified output stream.
*
+ * <p>
* The codec factory can be reused between multiple writers.
*
+ * <p>
* Returned writer can be used emit multiple top level element,
* but does not start / close parent JSON object, which must be done
* by user providing {@code jsonWriter} instance in order for
* @param jsonWriter JsonWriter
* @return A stream writer instance
*/
- public static NormalizedNodeStreamWriter createNestedWriter(final JSONCodecFactory codecFactory, final SchemaPath path, final URI initialNs, final JsonWriter jsonWriter) {
- return new JSONNormalizedNodeStreamWriter(codecFactory, path, jsonWriter, new JSONStreamWriterSharedRootContext(initialNs));
+ public static NormalizedNodeStreamWriter createNestedWriter(final JSONCodecFactory codecFactory,
+ final SchemaPath path, final URI initialNs, final JsonWriter jsonWriter) {
+ return new JSONNormalizedNodeStreamWriter(codecFactory, path, jsonWriter,
+ new JSONStreamWriterSharedRootContext(initialNs));
}
@Override
}
@SuppressWarnings("unchecked")
- private void writeValue(final Object value, final JSONCodec<?> codec)
- throws IOException {
- try {
- ((JSONCodec<Object>) codec).writeValue(writer, value);
- } catch (IOException | RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ private void writeValue(final Object value, final JSONCodec<?> codec) throws IOException {
+ ((JSONCodec<Object>) codec).writeValue(writer, value);
}
private void writeAnyXmlValue(final DOMSource anyXmlValue) throws IOException {
writer.beginObject();
inObject = true;
// name
- } else if (!inArray){
+ } else if (!inArray) {
writer.name(childNode.getNodeName());
}
}