1 package com.fasterxml.jackson.databind.exc; 2 3 import com.fasterxml.jackson.core.JsonGenerator; 4 import com.fasterxml.jackson.core.JsonParser; 5 import com.fasterxml.jackson.databind.BeanDescription; 6 import com.fasterxml.jackson.databind.JavaType; 7 import com.fasterxml.jackson.databind.JsonMappingException; 8 import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition; 9 10 /** 11 * Intermediate exception type used as the base class for all {@link JsonMappingException}s 12 * that are due to problems with target type definition; usually a problem with 13 * annotations used on a class or its properties. 14 * This is in contrast to {@link MismatchedInputException} which 15 * signals a problem with input to map. 16 * 17 * @since 2.9 18 */ 19 @SuppressWarnings("serial") 20 public class InvalidDefinitionException 21 extends JsonMappingException 22 { 23 protected final JavaType _type; 24 25 protected transient BeanDescription _beanDesc; 26 protected transient BeanPropertyDefinition _property; 27 InvalidDefinitionException(JsonParser p, String msg, JavaType type)28 protected InvalidDefinitionException(JsonParser p, String msg, 29 JavaType type) { 30 super(p, msg); 31 _type = type; 32 _beanDesc = null; 33 _property = null; 34 } 35 InvalidDefinitionException(JsonGenerator g, String msg, JavaType type)36 protected InvalidDefinitionException(JsonGenerator g, String msg, 37 JavaType type) { 38 super(g, msg); 39 _type = type; 40 _beanDesc = null; 41 _property = null; 42 } 43 InvalidDefinitionException(JsonParser p, String msg, BeanDescription bean, BeanPropertyDefinition prop)44 protected InvalidDefinitionException(JsonParser p, String msg, 45 BeanDescription bean, BeanPropertyDefinition prop) { 46 super(p, msg); 47 _type = (bean == null) ? null : bean.getType(); 48 _beanDesc = bean; 49 _property = prop; 50 } 51 InvalidDefinitionException(JsonGenerator g, String msg, BeanDescription bean, BeanPropertyDefinition prop)52 protected InvalidDefinitionException(JsonGenerator g, String msg, 53 BeanDescription bean, BeanPropertyDefinition prop) { 54 super(g, msg); 55 _type = (bean == null) ? null : bean.getType(); 56 _beanDesc = bean; 57 _property = prop; 58 } 59 from(JsonParser p, String msg, BeanDescription bean, BeanPropertyDefinition prop)60 public static InvalidDefinitionException from(JsonParser p, String msg, 61 BeanDescription bean, BeanPropertyDefinition prop) { 62 return new InvalidDefinitionException(p, msg, bean, prop); 63 } 64 from(JsonParser p, String msg, JavaType type)65 public static InvalidDefinitionException from(JsonParser p, String msg, 66 JavaType type) { 67 return new InvalidDefinitionException(p, msg, type); 68 } 69 from(JsonGenerator g, String msg, BeanDescription bean, BeanPropertyDefinition prop)70 public static InvalidDefinitionException from(JsonGenerator g, String msg, 71 BeanDescription bean, BeanPropertyDefinition prop) { 72 return new InvalidDefinitionException(g, msg, bean, prop); 73 } 74 from(JsonGenerator g, String msg, JavaType type)75 public static InvalidDefinitionException from(JsonGenerator g, String msg, 76 JavaType type) { 77 return new InvalidDefinitionException(g, msg, type); 78 } 79 80 /** 81 * Accessor for type fully resolved type that had the problem; this should always 82 * known and available, never <code>null</code> 83 */ getType()84 public JavaType getType() { 85 return _type; 86 } 87 88 /** 89 * Accessor for type definition (class) that had the definition problem, if any; may sometimes 90 * be undefined or unknown; if so, returns <code>null</code>. 91 */ getBeanDescription()92 public BeanDescription getBeanDescription() { 93 return _beanDesc; 94 } 95 96 /** 97 * Accessor for property that had the definition problem if any 98 * (none, for example if the problem relates to type in general), 99 * if known. If not known (or relevant), returns <code>null</code>. 100 */ getProperty()101 public BeanPropertyDefinition getProperty() { 102 return _property; 103 } 104 } 105