de.hakenadu.terms.gson.converter.DoubleConstantValueConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of composite-terms Show documentation
Show all versions of composite-terms Show documentation
A light extensible java 8+ library for creating composites of terms which are evaluatable using a visitor pattern.
The newest version!
package de.hakenadu.terms.gson.converter;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
public final class DoubleConstantValueConverter implements ConstantValueConverter {
@Override
public JsonElement toJson(final Double value) {
return new JsonPrimitive(value);
}
@Override
public Double fromJson(final JsonElement jsonElement) {
return NumberConstantValueConverter.getAsNumber(jsonElement)//
.map(Number::doubleValue)//
.orElseThrow(() -> new JsonParseException("not a double member: " + jsonElement));
}
@Override
public String getTypeName() {
return "double";
}
@Override
public Class getTypeClass() {
return Double.class;
}
}