1 package com.fasterxml.jackson.databind.introspect;
2 
3 import java.util.Collections;
4 import java.util.List;
5 
6 import com.fasterxml.jackson.annotation.JsonFormat;
7 import com.fasterxml.jackson.annotation.JsonInclude;
8 import com.fasterxml.jackson.databind.AnnotationIntrospector;
9 import com.fasterxml.jackson.databind.BeanProperty;
10 import com.fasterxml.jackson.databind.PropertyMetadata;
11 import com.fasterxml.jackson.databind.PropertyName;
12 import com.fasterxml.jackson.databind.cfg.MapperConfig;
13 
14 /**
15  * Intermediate {@link BeanProperty} class shared by concrete readable- and
16  * writable property implementations for sharing common functionality.
17  *
18  * @since 2.7
19  */
20 public abstract class ConcreteBeanPropertyBase
21     implements BeanProperty, java.io.Serializable
22 {
23     private static final long serialVersionUID = 1;
24 
25     /**
26      * Additional information about property
27      *
28      * @since 2.3
29      */
30     protected final PropertyMetadata _metadata;
31 
32     /**
33      * @since 2.9
34      */
35     protected transient List<PropertyName> _aliases;
36 
ConcreteBeanPropertyBase(PropertyMetadata md)37     protected ConcreteBeanPropertyBase(PropertyMetadata md) {
38         _metadata = (md == null) ? PropertyMetadata.STD_REQUIRED_OR_OPTIONAL : md;
39     }
40 
ConcreteBeanPropertyBase(ConcreteBeanPropertyBase src)41     protected ConcreteBeanPropertyBase(ConcreteBeanPropertyBase src) {
42         _metadata = src._metadata;
43     }
44 
45     @Override
isRequired()46     public boolean isRequired() { return _metadata.isRequired(); }
47 
48     @Override
getMetadata()49     public PropertyMetadata getMetadata() { return _metadata; }
50 
51     @Override
isVirtual()52     public boolean isVirtual() { return false; }
53 
54     @Override
55     @Deprecated
findFormatOverrides(AnnotationIntrospector intr)56     public final JsonFormat.Value findFormatOverrides(AnnotationIntrospector intr) {
57         JsonFormat.Value f = null;
58         if (intr != null) {
59             AnnotatedMember member = getMember();
60             if (member != null) {
61                 f = intr.findFormat(member);
62             }
63         }
64         if (f == null) {
65             f = EMPTY_FORMAT;
66         }
67         return f;
68     }
69 
70     @Override
findPropertyFormat(MapperConfig<?> config, Class<?> baseType)71     public JsonFormat.Value findPropertyFormat(MapperConfig<?> config, Class<?> baseType)
72     {
73         JsonFormat.Value v1 = config.getDefaultPropertyFormat(baseType);
74         JsonFormat.Value v2 = null;
75         AnnotationIntrospector intr = config.getAnnotationIntrospector();
76         if (intr != null) {
77             AnnotatedMember member = getMember();
78             if (member != null) {
79                 v2 = intr.findFormat(member);
80             }
81         }
82         if (v1 == null) {
83             return (v2 == null) ? EMPTY_FORMAT : v2;
84         }
85         return (v2 == null) ? v1 : v1.withOverrides(v2);
86     }
87 
88     @Override
findPropertyInclusion(MapperConfig<?> config, Class<?> baseType)89     public JsonInclude.Value findPropertyInclusion(MapperConfig<?> config, Class<?> baseType)
90     {
91         AnnotationIntrospector intr = config.getAnnotationIntrospector();
92         AnnotatedMember member = getMember();
93         if (member == null) {
94             JsonInclude.Value def = config.getDefaultPropertyInclusion(baseType);
95             return def;
96         }
97         JsonInclude.Value v0 = config.getDefaultInclusion(baseType, member.getRawType());
98         if (intr == null) {
99             return v0;
100         }
101         JsonInclude.Value v = intr.findPropertyInclusion(member);
102         if (v0 == null) {
103             return v;
104         }
105         return v0.withOverrides(v);
106     }
107 
108     @Override
findAliases(MapperConfig<?> config)109     public List<PropertyName> findAliases(MapperConfig<?> config)
110     {
111         List<PropertyName> aliases = _aliases;
112         if (aliases == null) {
113             AnnotationIntrospector intr = config.getAnnotationIntrospector();
114             if (intr != null) {
115                 final AnnotatedMember member = getMember();
116                 if (member != null) {
117                     aliases = intr.findPropertyAliases(member);
118                 }
119             }
120             if (aliases == null) {
121                 aliases = Collections.emptyList();
122             }
123             _aliases = aliases;
124         }
125         return aliases;
126     }
127 }
128