• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.introspect;
2 
3 import com.fasterxml.jackson.annotation.JsonIdentityInfo;
4 import com.fasterxml.jackson.annotation.ObjectIdGenerator;
5 import com.fasterxml.jackson.annotation.ObjectIdResolver;
6 import com.fasterxml.jackson.annotation.SimpleObjectIdResolver;
7 import com.fasterxml.jackson.databind.PropertyName;
8 import com.fasterxml.jackson.databind.util.ClassUtil;
9 
10 /**
11  * Container object that encapsulates information usually
12  * derived from {@link JsonIdentityInfo} annotation or its
13  * custom alternatives
14  */
15 public class ObjectIdInfo
16 {
17     protected final PropertyName _propertyName;
18     protected final Class<? extends ObjectIdGenerator<?>> _generator;
19     protected final Class<? extends ObjectIdResolver> _resolver;
20     protected final Class<?> _scope;
21     protected final boolean _alwaysAsId;
22 
23     /**
24      * @since 2.8.9
25      */
26     private final static ObjectIdInfo EMPTY = new ObjectIdInfo(PropertyName.NO_NAME, Object.class, null, false, null);
27 
ObjectIdInfo(PropertyName name, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen, Class<? extends ObjectIdResolver> resolver)28     public ObjectIdInfo(PropertyName name, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen,
29             Class<? extends ObjectIdResolver> resolver)
30     {
31         this(name, scope, gen, false, resolver);
32     }
33 
ObjectIdInfo(PropertyName prop, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen, boolean alwaysAsId)34     protected ObjectIdInfo(PropertyName prop, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen,
35             boolean alwaysAsId)
36     {
37         this(prop, scope, gen, alwaysAsId, SimpleObjectIdResolver.class);
38 
39     }
40 
ObjectIdInfo(PropertyName prop, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen, boolean alwaysAsId, Class<? extends ObjectIdResolver> resolver)41     protected ObjectIdInfo(PropertyName prop, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen,
42             boolean alwaysAsId, Class<? extends ObjectIdResolver> resolver)
43     {
44         _propertyName = prop;
45         _scope = scope;
46         _generator = gen;
47         _alwaysAsId = alwaysAsId;
48         if (resolver == null) {
49             resolver = SimpleObjectIdResolver.class;
50         }
51         _resolver = resolver;
52     }
53 
empty()54     public static ObjectIdInfo empty() {
55         return EMPTY;
56     }
57 
withAlwaysAsId(boolean state)58     public ObjectIdInfo withAlwaysAsId(boolean state) {
59         if (_alwaysAsId == state) {
60             return this;
61         }
62         return new ObjectIdInfo(_propertyName, _scope, _generator, state, _resolver);
63     }
64 
getPropertyName()65     public PropertyName getPropertyName() { return _propertyName; }
getScope()66     public Class<?> getScope() { return _scope; }
getGeneratorType()67     public Class<? extends ObjectIdGenerator<?>> getGeneratorType() { return _generator; }
getResolverType()68     public Class<? extends ObjectIdResolver> getResolverType() { return _resolver; }
getAlwaysAsId()69     public boolean getAlwaysAsId() { return _alwaysAsId; }
70 
71     @Override
toString()72     public String toString() {
73         return "ObjectIdInfo: propName="+_propertyName
74                 +", scope="+ClassUtil.nameOf(_scope)
75                 +", generatorType="+ClassUtil.nameOf(_generator)
76                 +", alwaysAsId="+_alwaysAsId;
77     }
78 }
79