1 package com.fasterxml.jackson.databind.deser; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 import java.util.List; 6 7 import com.fasterxml.jackson.core.JsonLocation; 8 import com.fasterxml.jackson.core.JsonParser; 9 10 import com.fasterxml.jackson.databind.JsonMappingException; 11 import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId; 12 13 /** 14 * Exception thrown during deserialization when there are object id that can't 15 * be resolved. 16 * 17 * @author pgelinas 18 */ 19 public class UnresolvedForwardReference extends JsonMappingException { 20 private static final long serialVersionUID = 1L; 21 private ReadableObjectId _roid; 22 private List<UnresolvedId> _unresolvedIds; 23 24 /** 25 * @since 2.7 26 */ UnresolvedForwardReference(JsonParser p, String msg, JsonLocation loc, ReadableObjectId roid)27 public UnresolvedForwardReference(JsonParser p, String msg, JsonLocation loc, ReadableObjectId roid) { 28 super(p, msg, loc); 29 _roid = roid; 30 } 31 32 /** 33 * @since 2.7 34 */ UnresolvedForwardReference(JsonParser p, String msg)35 public UnresolvedForwardReference(JsonParser p, String msg) { 36 super(p, msg); 37 _unresolvedIds = new ArrayList<UnresolvedId>(); 38 } 39 40 /** 41 * @deprecated Since 2.7 42 */ 43 @Deprecated // since 2.7 UnresolvedForwardReference(String msg, JsonLocation loc, ReadableObjectId roid)44 public UnresolvedForwardReference(String msg, JsonLocation loc, ReadableObjectId roid) { 45 super(msg, loc); 46 _roid = roid; 47 } 48 49 /** 50 * @deprecated Since 2.7 51 */ 52 @Deprecated // since 2.7 UnresolvedForwardReference(String msg)53 public UnresolvedForwardReference(String msg) { 54 super(msg); 55 _unresolvedIds = new ArrayList<UnresolvedId>(); 56 } 57 58 /* 59 /********************************************************** 60 /* Accessor methods 61 /********************************************************** 62 */ 63 getRoid()64 public ReadableObjectId getRoid() { 65 return _roid; 66 } 67 getUnresolvedId()68 public Object getUnresolvedId() { 69 return _roid.getKey().key; 70 } 71 addUnresolvedId(Object id, Class<?> type, JsonLocation where)72 public void addUnresolvedId(Object id, Class<?> type, JsonLocation where) { 73 _unresolvedIds.add(new UnresolvedId(id, type, where)); 74 } 75 getUnresolvedIds()76 public List<UnresolvedId> getUnresolvedIds(){ 77 return _unresolvedIds; 78 } 79 80 @Override getMessage()81 public String getMessage() 82 { 83 String msg = super.getMessage(); 84 if (_unresolvedIds == null) { 85 return msg; 86 } 87 88 StringBuilder sb = new StringBuilder(msg); 89 Iterator<UnresolvedId> iterator = _unresolvedIds.iterator(); 90 while (iterator.hasNext()) { 91 UnresolvedId unresolvedId = iterator.next(); 92 sb.append(unresolvedId.toString()); 93 if (iterator.hasNext()) { 94 sb.append(", "); 95 } 96 } 97 sb.append('.'); 98 return sb.toString(); 99 } 100 } 101