se.fortnox.reactivewizard.jaxrs.params.deserializing.NumberDeserializer Maven / Gradle / Ivy
package se.fortnox.reactivewizard.jaxrs.params.deserializing;
import java.util.function.Function;
/**
* Generic number deserializer.
*/
public abstract class NumberDeserializer implements Deserializer {
protected String errorCode;
private Function numberParser;
public NumberDeserializer(Function numberParser, String errorCode) {
this.numberParser = numberParser;
this.errorCode = errorCode;
}
@Override
public T deserialize(String value) throws DeserializerException {
if (value == null) {
return getNullValue();
}
try {
return numberParser.apply(value);
} catch (NumberFormatException e) {
throw new DeserializerException(errorCode);
}
}
protected T getNullValue() throws DeserializerException {
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy