1 package com.fasterxml.jackson.databind.exc; 2 3 import com.fasterxml.jackson.databind.DeserializationContext; 4 import com.fasterxml.jackson.databind.JavaType; 5 import com.fasterxml.jackson.databind.PropertyName; 6 import com.fasterxml.jackson.databind.util.ClassUtil; 7 8 /** 9 * Exception thrown if a `null` value is being encountered for a property 10 * designed as "fail on null" property (see {@link com.fasterxml.jackson.annotation.JsonSetter}). 11 * 12 * @since 2.9 13 */ 14 public class InvalidNullException 15 extends MismatchedInputException // since 2.9 16 { 17 private static final long serialVersionUID = 1L; // silly Eclipse, warnings 18 19 /** 20 * Name of property, if known, for which null was encountered. 21 */ 22 protected final PropertyName _propertyName; 23 24 /* 25 /********************************************************** 26 /* Life-cycle 27 /********************************************************** 28 */ 29 InvalidNullException(DeserializationContext ctxt, String msg, PropertyName pname)30 protected InvalidNullException(DeserializationContext ctxt, String msg, 31 PropertyName pname) 32 { 33 super(ctxt.getParser(), msg); 34 _propertyName = pname; 35 } 36 from(DeserializationContext ctxt, PropertyName name, JavaType type)37 public static InvalidNullException from(DeserializationContext ctxt, 38 PropertyName name, JavaType type) 39 { 40 String msg = String.format("Invalid `null` value encountered for property %s", 41 ClassUtil.quotedOr(name, "<UNKNOWN>")); 42 InvalidNullException exc = new InvalidNullException(ctxt, msg, name); 43 if (type != null) { 44 exc.setTargetType(type); 45 } 46 return exc; 47 } 48 getPropertyName()49 public PropertyName getPropertyName() { 50 return _propertyName; 51 } 52 } 53