com.fitbur.fasterxml.jackson.databind.deser.impl.NullProvider Maven / Gradle / Ivy
package com.fitbur.fasterxml.jackson.databind.com.fitburser.impl;
import com.fitbur.fasterxml.jackson.core.JsonProcessingException;
import com.fitbur.fasterxml.jackson.databind.DeserializationContext;
import com.fitbur.fasterxml.jackson.databind.DeserializationFeature;
import com.fitbur.fasterxml.jackson.databind.JavaType;
/**
* To support [JACKSON-420] we need bit more indirection; this is used to produce
* artificial failure for primitives that don't accept JSON null as value.
*/
public final class NullProvider
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
private final Object _nullValue;
private final boolean _isPrimitive;
private final Class> _rawType;
public NullProvider(JavaType type, Object nullValue)
{
_nullValue = nullValue;
// [JACKSON-420]
_isPrimitive = type.isPrimitive();
_rawType = type.getRawClass();
}
public Object nullValue(DeserializationContext ctxt) throws JsonProcessingException
{
if (_isPrimitive && ctxt.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)) {
throw ctxt.mappingException("Can not map JSON null into type "+_rawType.getName()
+" (set DeserializationConfig.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES to 'false' to allow)");
}
return _nullValue;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy