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

dsl_json.java.util.OptionalDoubleDslJsonConverter Maven / Gradle / Ivy

There is a newer version: 1.10.0
Show newest version
package dsl_json.java.util;

import com.dslplatform.json.*;

import java.io.IOException;
import java.util.OptionalDouble;

public class OptionalDoubleDslJsonConverter implements Configuration {
	@Override
	public void configure(DslJson json) {
		json.registerWriter(OptionalDouble.class, new JsonWriter.WriteObject() {
			@Override
			public void write(JsonWriter writer, @Nullable OptionalDouble value) {
				if (value != null && value.isPresent()) NumberConverter.serialize(value.getAsDouble(), writer);
				else writer.writeNull();
			}
		});
		json.registerReader(OptionalDouble.class, new JsonReader.ReadObject() {
			@Override
			public OptionalDouble read(JsonReader reader) throws IOException {
				return reader.wasNull() ? OptionalDouble.empty() : OptionalDouble.of(NumberConverter.deserializeDouble(reader));
			}
		});
		json.registerDefault(OptionalDouble.class, OptionalDouble.empty());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy