dsl_json.java.lang.ByteDslJsonConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dsl-json-java8 Show documentation
Show all versions of dsl-json-java8 Show documentation
DSL Platform compatible Java JSON library (https://dsl-platform.com)
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);
}
}