All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dslplatform.json.runtime.WriteDescription Maven / Gradle / Ivy

There is a newer version: 1.10.0
Show newest version
package com.dslplatform.json.runtime;

import com.dslplatform.json.JsonWriter;

abstract class WriteDescription implements JsonWriter.WriteObject {

	private final JsonWriter.WriteObject[] writers;

	WriteDescription(final JsonWriter.WriteObject[] writers) {
		if (writers == null) throw new IllegalArgumentException("writers can't be null");
		this.writers = writers.clone();
	}

	public final void write(final JsonWriter writer, final T instance) {
		if (instance == null) {
			writer.writeNull();
		} else {
			writer.writeByte(JsonWriter.OBJECT_START);
			int pos = writer.size();
			long flushed = writer.flushed();
			if (writers.length > 0) {
				writers[0].write(writer, instance);
				for (int i = 1; i < writers.length; i++) {
					if (writer.size() != pos || writer.flushed() != flushed) {
						writer.writeByte(JsonWriter.COMMA);
						pos = writer.size();
						flushed = writer.flushed();
					}
					writers[i].write(writer, instance);
				}
			}
			writer.writeByte(JsonWriter.OBJECT_END);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy