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

dsl_json.java.lang.ByteDslJsonConverter Maven / Gradle / Ivy

The newest version!
package dsl_json.java.lang;

import com.dslplatform.json.*;

import java.io.IOException;

public class ByteDslJsonConverter implements Configuration {
	private static final JsonWriter.WriteObject ByteWriter = new JsonWriter.WriteObject() {
		@Override
		public void write(JsonWriter writer, @Nullable Byte value) {
			if (value == null) writer.writeNull();
			else NumberConverter.serialize(value, writer);
		}
	};
	private static final JsonReader.ReadObject ByteReader = new JsonReader.ReadObject() {
		@Override
		public Byte read(JsonReader reader) throws IOException {
			return (byte)NumberConverter.deserializeInt(reader);
		}
	};
	private static final JsonReader.ReadObject NullableByteReader = new JsonReader.ReadObject() {
		@Nullable
		@Override
		public Byte read(JsonReader reader) throws IOException {
			return reader.wasNull() ? null : (byte)NumberConverter.deserializeInt(reader);
		}
	};

	@Override
	public void configure(DslJson json) {
		json.registerWriter(byte.class, ByteWriter);
		json.registerReader(byte.class, ByteReader);
		json.registerWriter(Byte.class, ByteWriter);
		json.registerReader(Byte.class, NullableByteReader);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy