1 package com.fasterxml.jackson.databind.deser.impl; 2 3 import com.fasterxml.jackson.databind.*; 4 import com.fasterxml.jackson.databind.deser.NullValueProvider; 5 import com.fasterxml.jackson.databind.exc.InvalidNullException; 6 import com.fasterxml.jackson.databind.util.AccessPattern; 7 8 /** 9 * Simple {@link NullValueProvider} that will always throw a 10 * {@link InvalidNullException} when a null is encountered. 11 */ 12 public class NullsFailProvider 13 implements NullValueProvider, java.io.Serializable 14 { 15 private static final long serialVersionUID = 1L; 16 17 protected final PropertyName _name; 18 protected final JavaType _type; 19 NullsFailProvider(PropertyName name, JavaType type)20 protected NullsFailProvider(PropertyName name, JavaType type) { 21 _name = name; 22 _type = type; 23 } 24 constructForProperty(BeanProperty prop)25 public static NullsFailProvider constructForProperty(BeanProperty prop) { 26 return constructForProperty(prop, prop.getType()); 27 } 28 29 // @since 2.10.2 constructForProperty(BeanProperty prop, JavaType type)30 public static NullsFailProvider constructForProperty(BeanProperty prop, JavaType type) { 31 return new NullsFailProvider(prop.getFullName(), type); 32 } 33 constructForRootValue(JavaType t)34 public static NullsFailProvider constructForRootValue(JavaType t) { 35 return new NullsFailProvider(null, t); 36 } 37 38 @Override getNullAccessPattern()39 public AccessPattern getNullAccessPattern() { 40 // Must be called every time to effect the exception... 41 return AccessPattern.DYNAMIC; 42 } 43 44 @Override getNullValue(DeserializationContext ctxt)45 public Object getNullValue(DeserializationContext ctxt) 46 throws JsonMappingException { 47 throw InvalidNullException.from(ctxt, _name, _type); 48 } 49 } 50