Skip to content

Commit e016358

Browse files
committed
Incremental changes to try to refactor type (de)serializer handling from annotations, default type handling (eventually)
1 parent 838ae27 commit e016358

File tree

13 files changed

+148
-123
lines changed

13 files changed

+148
-123
lines changed

src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public abstract class AnnotationIntrospector
4242
implements Versioned, java.io.Serializable
4343
{
4444
/*
45-
/**********************************************************
45+
/**********************************************************************
4646
/* Helper types
47-
/**********************************************************
47+
/**********************************************************************
4848
*/
4949

5050
/**
@@ -92,9 +92,9 @@ public ReferenceProperty(Type t, String n) {
9292
}
9393

9494
/*
95-
/**********************************************************
95+
/**********************************************************************
9696
/* Factory methods
97-
/**********************************************************
97+
/**********************************************************************
9898
*/
9999

100100
/**
@@ -111,9 +111,9 @@ public static AnnotationIntrospector pair(AnnotationIntrospector a1, AnnotationI
111111
}
112112

113113
/*
114-
/**********************************************************
114+
/**********************************************************************
115115
/* Access to possibly chained introspectors
116-
/**********************************************************
116+
/**********************************************************************
117117
*/
118118

119119
/**
@@ -147,18 +147,18 @@ public Collection<AnnotationIntrospector> allIntrospectors(Collection<Annotation
147147
}
148148

149149
/*
150-
/**********************************************************
150+
/**********************************************************************
151151
/* Default Versioned impl
152-
/**********************************************************
152+
/**********************************************************************
153153
*/
154154

155155
@Override
156156
public abstract Version version();
157157

158158
/*
159-
/**********************************************************
159+
/**********************************************************************
160160
/* Meta-annotations (annotations for annotation types)
161-
/**********************************************************
161+
/**********************************************************************
162162
*/
163163

164164
/**
@@ -171,9 +171,9 @@ public boolean isAnnotationBundle(Annotation ann) {
171171
}
172172

173173
/*
174-
/**********************************************************
174+
/**********************************************************************
175175
/* Annotations for Object Id handling
176-
/**********************************************************
176+
/**********************************************************************
177177
*/
178178

179179
/**
@@ -196,9 +196,9 @@ public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectId
196196
}
197197

198198
/*
199-
/**********************************************************
199+
/**********************************************************************
200200
/* General class annotations
201-
/**********************************************************
201+
/**********************************************************************
202202
*/
203203

204204
/**
@@ -269,9 +269,9 @@ public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated ac)
269269
public String findClassDescription(AnnotatedClass ac) { return null; }
270270

271271
/*
272-
/**********************************************************
272+
/**********************************************************************
273273
/* Property auto-detection
274-
/**********************************************************
274+
/**********************************************************************
275275
*/
276276

277277
/**
@@ -286,11 +286,23 @@ public VisibilityChecker findAutoDetectVisibility(AnnotatedClass ac, VisibilityC
286286
}
287287

288288
/*
289-
/**********************************************************
289+
/**********************************************************************
290290
/* Annotations for Polymorphic type handling
291-
/**********************************************************
291+
/**********************************************************************
292292
*/
293-
293+
294+
/**
295+
* Method for checking whether given Class or Property Accessor specifies
296+
* polymorphic type-handling information, to indicate need for polymorphic
297+
* handling.
298+
*
299+
* @since 3.0
300+
*/
301+
public JsonTypeInfo.Value findPolymorphicTypeInfo(MapperConfig<?> config,
302+
Annotated ann) {
303+
return null;
304+
}
305+
294306
/**
295307
* Method for checking if given class has annotations that indicate
296308
* that specific type resolver is to be used for handling instances.
@@ -300,13 +312,12 @@ public VisibilityChecker findAutoDetectVisibility(AnnotatedClass ac, VisibilityC
300312
* {@link #findSubtypes}
301313
*
302314
* @param config Configuration settings in effect (for serialization or deserialization)
303-
* @param ac Annotated class to check for annotations
304315
* @param baseType Base java type of value for which resolver is to be found
305316
*
306317
* @return Type resolver builder for given type, if one found; null if none
307318
*/
308319
public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config,
309-
AnnotatedClass ac, JavaType baseType) {
320+
Annotated ann, JavaType baseType, JsonTypeInfo.Value typeInfo) {
310321
return null;
311322
}
312323

@@ -319,14 +330,13 @@ public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config,
319330
* {@link #findSubtypes}
320331
*
321332
* @param config Configuration settings in effect (for serialization or deserialization)
322-
* @param am Annotated member (field or method) to check for annotations
323333
* @param baseType Base java type of property for which resolver is to be found
324334
*
325335
* @return Type resolver builder for properties of given entity, if one found;
326336
* null if none
327337
*/
328338
public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config,
329-
AnnotatedMember am, JavaType baseType) {
339+
Annotated ann, JavaType baseType, JsonTypeInfo.Value typeInfo) {
330340
return null;
331341
}
332342

@@ -341,14 +351,13 @@ public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config,
341351
* {@link #findSubtypes}
342352
*
343353
* @param config Configuration settings in effect (for serialization or deserialization)
344-
* @param am Annotated member (field or method) to check for annotations
345354
* @param containerType Type of property for which resolver is to be found (must be a container type)
346355
*
347356
* @return Type resolver builder for values contained in properties of given entity,
348357
* if one found; null if none
349358
*/
350359
public TypeResolverBuilder<?> findPropertyContentTypeResolver(MapperConfig<?> config,
351-
AnnotatedMember am, JavaType containerType) {
360+
Annotated ann, JavaType containerType, JsonTypeInfo.Value typeInfo) {
352361
return null;
353362
}
354363

src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,12 @@ public TypeDeserializer findTypeDeserializer(JavaType baseType)
631631
{
632632
BeanDescription bean = introspectClassAnnotations(baseType.getRawClass());
633633
AnnotatedClass ac = bean.getClassInfo();
634-
TypeResolverBuilder<?> b = getAnnotationIntrospector().findTypeResolver(this, ac, baseType);
634+
AnnotationIntrospector ai = getAnnotationIntrospector();
635+
TypeResolverBuilder<?> b = ai.findTypeResolver(this, ac, baseType,
636+
ai.findPolymorphicTypeInfo(this, ac));
635637

636-
/* Ok: if there is no explicit type info handler, we may want to
637-
* use a default. If so, config object knows what to use.
638-
*/
638+
// Ok: if there is no explicit type info handler, we may want to
639+
// use a default. If so, config object knows what to use.
639640
Collection<NamedType> subtypes = null;
640641
if (b == null) {
641642
b = getDefaultTyper(baseType);

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,6 @@ public Object handleUnexpectedToken(Class<?> instClass, JsonToken t,
12001200
*
12011201
* @throws IOException To indicate unrecoverable problem, if resolution cannot
12021202
* be made to work
1203-
*
1204-
* @since 2.8
12051203
*/
12061204
public JavaType handleUnknownTypeId(JavaType baseType, String id,
12071205
TypeIdResolver idResolver, String extraDesc) throws IOException
@@ -1230,9 +1228,6 @@ public JavaType handleUnknownTypeId(JavaType baseType, String id,
12301228
throw invalidTypeIdException(baseType, id, extraDesc);
12311229
}
12321230

1233-
/**
1234-
* @since 2.9
1235-
*/
12361231
public JavaType handleMissingTypeId(JavaType baseType,
12371232
TypeIdResolver idResolver, String extraDesc) throws IOException
12381233
{

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,8 @@ public TypeDeserializer findTypeDeserializer(DeserializationConfig config,
16111611
BeanDescription bean = config.introspectClassAnnotations(baseType.getRawClass());
16121612
AnnotatedClass ac = bean.getClassInfo();
16131613
AnnotationIntrospector ai = config.getAnnotationIntrospector();
1614-
TypeResolverBuilder<?> b = ai.findTypeResolver(config, ac, baseType);
1614+
TypeResolverBuilder<?> b = ai.findTypeResolver(config,
1615+
ac, baseType, ai.findPolymorphicTypeInfo(config, ac));
16151616

16161617
/* Ok: if there is no explicit type info handler, we may want to
16171618
* use a default. If so, config object knows what to use.
@@ -1762,7 +1763,9 @@ public TypeDeserializer findPropertyTypeDeserializer(DeserializationConfig confi
17621763
throws JsonMappingException
17631764
{
17641765
AnnotationIntrospector ai = config.getAnnotationIntrospector();
1765-
TypeResolverBuilder<?> b = ai.findPropertyTypeResolver(config, annotated, baseType);
1766+
TypeResolverBuilder<?> b = ai.findPropertyTypeResolver(config,
1767+
annotated, baseType,
1768+
ai.findPolymorphicTypeInfo(config, annotated));
17661769
// Defaulting: if no annotations on member, check value class
17671770
if (b == null) {
17681771
return findTypeDeserializer(config, baseType);
@@ -1789,7 +1792,9 @@ public TypeDeserializer findPropertyContentTypeDeserializer(DeserializationConfi
17891792
throws JsonMappingException
17901793
{
17911794
AnnotationIntrospector ai = config.getAnnotationIntrospector();
1792-
TypeResolverBuilder<?> b = ai.findPropertyContentTypeResolver(config, propertyEntity, containerType);
1795+
TypeResolverBuilder<?> b = ai.findPropertyContentTypeResolver(config,
1796+
propertyEntity, containerType,
1797+
ai.findPolymorphicTypeInfo(config, propertyEntity));
17931798
JavaType contentType = containerType.getContentType();
17941799
// Defaulting: if no annotations on member, check class
17951800
if (b == null) {

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.fasterxml.jackson.annotation.JsonInclude;
1313
import com.fasterxml.jackson.annotation.JsonProperty;
1414
import com.fasterxml.jackson.annotation.JsonSetter;
15+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
1516
import com.fasterxml.jackson.core.Version;
1617
import com.fasterxml.jackson.databind.*;
1718
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -91,9 +92,9 @@ public boolean isAnnotationBundle(Annotation ann) {
9192
}
9293

9394
/*
94-
/******************************************************
95+
/**********************************************************************
9596
/* General class annotations
96-
/******************************************************
97+
/**********************************************************************
9798
*/
9899

99100
@Override
@@ -160,10 +161,10 @@ public String findClassDescription(AnnotatedClass ac) {
160161
}
161162

162163
/*
163-
/******************************************************
164+
/**********************************************************************
164165
/* Property auto-detection
165-
/******************************************************
166-
*/
166+
/**********************************************************************
167+
*/
167168

168169
@Override
169170
public VisibilityChecker findAutoDetectVisibility(AnnotatedClass ac,
@@ -177,40 +178,51 @@ public VisibilityChecker findAutoDetectVisibility(AnnotatedClass ac,
177178
}
178179

179180
/*
180-
/******************************************************
181+
/**********************************************************************
181182
/* Type handling
182-
/******************************************************
183+
/**********************************************************************
183184
*/
184185

186+
@Override
187+
public JsonTypeInfo.Value findPolymorphicTypeInfo(MapperConfig<?> config,
188+
Annotated ann)
189+
{
190+
JsonTypeInfo.Value v = _primary.findPolymorphicTypeInfo(config, ann);
191+
if (v == null) {
192+
v = _secondary.findPolymorphicTypeInfo(config, ann);
193+
}
194+
return v;
195+
}
196+
185197
@Override
186198
public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config,
187-
AnnotatedClass ac, JavaType baseType)
199+
Annotated ann, JavaType baseType, JsonTypeInfo.Value typeInfo)
188200
{
189-
TypeResolverBuilder<?> b = _primary.findTypeResolver(config, ac, baseType);
201+
TypeResolverBuilder<?> b = _primary.findTypeResolver(config, ann, baseType, typeInfo);
190202
if (b == null) {
191-
b = _secondary.findTypeResolver(config, ac, baseType);
203+
b = _secondary.findTypeResolver(config, ann, baseType, typeInfo);
192204
}
193205
return b;
194206
}
195207

196208
@Override
197209
public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config,
198-
AnnotatedMember am, JavaType baseType)
210+
Annotated ann, JavaType baseType, JsonTypeInfo.Value typeInfo)
199211
{
200-
TypeResolverBuilder<?> b = _primary.findPropertyTypeResolver(config, am, baseType);
212+
TypeResolverBuilder<?> b = _primary.findPropertyTypeResolver(config, ann, baseType, typeInfo);
201213
if (b == null) {
202-
b = _secondary.findPropertyTypeResolver(config, am, baseType);
214+
b = _secondary.findPropertyTypeResolver(config, ann, baseType, typeInfo);
203215
}
204216
return b;
205217
}
206218

207219
@Override
208220
public TypeResolverBuilder<?> findPropertyContentTypeResolver(MapperConfig<?> config,
209-
AnnotatedMember am, JavaType baseType)
221+
Annotated ann, JavaType baseType, JsonTypeInfo.Value typeInfo)
210222
{
211-
TypeResolverBuilder<?> b = _primary.findPropertyContentTypeResolver(config, am, baseType);
223+
TypeResolverBuilder<?> b = _primary.findPropertyContentTypeResolver(config, ann, baseType, typeInfo);
212224
if (b == null) {
213-
b = _secondary.findPropertyContentTypeResolver(config, am, baseType);
225+
b = _secondary.findPropertyContentTypeResolver(config, ann, baseType, typeInfo);
214226
}
215227
return b;
216228
}
@@ -237,10 +249,11 @@ public String findTypeName(AnnotatedClass ac)
237249
}
238250
return name;
239251
}
252+
240253
/*
241-
/******************************************************
254+
/**********************************************************************
242255
/* General member (field, method/constructor) annotations
243-
/******************************************************
256+
/**********************************************************************
244257
*/
245258

246259
@Override

0 commit comments

Comments
 (0)