1
2
3
4
5
6
7
8
9
10
11
12
13
14 package com.addthis.codec.jackson;
15
16 import java.util.Collection;
17
18 import com.fasterxml.jackson.core.JsonLocation;
19 import com.fasterxml.jackson.core.JsonParser;
20 import com.fasterxml.jackson.databind.exc.PropertyBindingException;
21
22 public class MissingPropertyException extends PropertyBindingException {
23
24 public MissingPropertyException(String msg,
25 JsonLocation loc,
26 Class<?> referringClass,
27 String propName,
28 Collection<Object> propertyIds) {
29 super(msg, loc, referringClass, propName, propertyIds);
30 }
31
32 public static MissingPropertyException from(JsonParser jp,
33 Object fromObjectOrClass, String propertyName,
34 Collection<Object> propertyIds) {
35 if (fromObjectOrClass == null) {
36 throw new IllegalArgumentException();
37 }
38 Class<?> ref;
39 if (fromObjectOrClass instanceof Class<?>) {
40 ref = (Class<?>) fromObjectOrClass;
41 } else {
42 ref = fromObjectOrClass.getClass();
43 }
44 String msg = "Missing field \""+propertyName+"\" (class "+ref.getName()+"), marked as required";
45 MissingPropertyException e = new MissingPropertyException(
46 msg, jp.getCurrentLocation(), ref, propertyName, propertyIds);
47
48 e.prependPath(fromObjectOrClass, propertyName);
49 return e;
50 }
51 }