Skip to content

Commit ed5eab2

Browse files
Merge branch 'master' into 4781
2 parents 66d8f95 + 9279ae3 commit ed5eab2

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/AbstractModelConverter.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
public abstract class AbstractModelConverter implements ModelConverter {
2323
protected final ObjectMapper _mapper;
24-
protected final AnnotationIntrospector _intr;
2524
protected final TypeNameResolver _typeNameResolver;
2625
/**
2726
* Minor optimization: no need to keep on resolving same types over and over
@@ -43,7 +42,6 @@ public void setupModule(SetupContext context) {
4342
});
4443
_mapper = mapper;
4544
_typeNameResolver = typeNameResolver;
46-
_intr = mapper.getSerializationConfig().getAnnotationIntrospector();
4745
}
4846

4947
@Override
@@ -55,6 +53,17 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
5553
}
5654
}
5755

56+
/**
57+
* Retrieves the current AnnotationIntrospector from the ObjectMapper's serialization configuration.
58+
* We do not cache the value of _intr because users can load jackson modules later,
59+
* and we want to use their annotation inspection.
60+
*
61+
* @return the current AnnotationIntrospector
62+
*/
63+
protected AnnotationIntrospector _intr() {
64+
return _mapper.getSerializationConfig().getAnnotationIntrospector();
65+
}
66+
5867
protected String _typeName(JavaType type) {
5968
return _typeName(type, null);
6069
}
@@ -89,7 +98,7 @@ protected String _findTypeName(JavaType type, BeanDescription beanDesc) {
8998
beanDesc = _mapper.getSerializationConfig().introspectClassAnnotations(type);
9099
}
91100

92-
PropertyName rootName = _intr.findRootName(beanDesc.getClassInfo());
101+
PropertyName rootName = _intr().findRootName(beanDesc.getClassInfo());
93102
if (rootName != null && rootName.hasSimpleName()) {
94103
return rootName.getSimpleName();
95104
}

modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ private Schema clone(Schema property) {
11911191

11921192
private boolean isSubtype(AnnotatedClass childClass, Class<?> parentClass) {
11931193
final BeanDescription parentDesc = _mapper.getSerializationConfig().introspectClassAnnotations(parentClass);
1194-
List<NamedType> subTypes =_intr.findSubtypes(parentDesc.getClassInfo());
1194+
List<NamedType> subTypes = _intr().findSubtypes(parentDesc.getClassInfo());
11951195
if (subTypes == null) {
11961196
return false;
11971197
}
@@ -1238,7 +1238,7 @@ protected void _addEnumProps(Class<?> propClass, Schema property) {
12381238
Enum<?>[] enumConstants = enumClass.getEnumConstants();
12391239

12401240
if (enumConstants != null) {
1241-
String[] enumValues = _intr.findEnumValues(propClass, enumConstants,
1241+
String[] enumValues = _intr().findEnumValues(propClass, enumConstants,
12421242
new String[enumConstants.length]);
12431243

12441244
for (Enum<?> en : enumConstants) {
@@ -1264,7 +1264,7 @@ protected void _addEnumProps(Class<?> propClass, Schema property) {
12641264
} else if (useToString) {
12651265
n = en.toString();
12661266
} else {
1267-
n = _intr.findEnumValue(en);
1267+
n = _intr().findEnumValue(en);
12681268
}
12691269
if (property instanceof StringSchema) {
12701270
StringSchema sp = (StringSchema) property;
@@ -1641,7 +1641,7 @@ protected void applyBeanValidatorAnnotations(Schema property, Annotation[] annot
16411641
}
16421642

16431643
private boolean resolveSubtypes(Schema model, BeanDescription bean, ModelConverterContext context, JsonView jsonViewAnnotation) {
1644-
final List<NamedType> types = _intr.findSubtypes(bean.getClassInfo());
1644+
final List<NamedType> types = _intr().findSubtypes(bean.getClassInfo());
16451645
if (types == null) {
16461646
return false;
16471647
}
@@ -1777,7 +1777,7 @@ private void removeSuperClassAndInterfaceSubTypes(List<NamedType> types, BeanDes
17771777
private void removeSuperSubTypes(List<NamedType> resultTypes, Class<?> superClass) {
17781778
JavaType superType = _mapper.constructType(superClass);
17791779
BeanDescription superBean = _mapper.getSerializationConfig().introspect(superType);
1780-
final List<NamedType> superTypes = _intr.findSubtypes(superBean.getClassInfo());
1780+
final List<NamedType> superTypes = _intr().findSubtypes(superBean.getClassInfo());
17811781
if (superTypes != null) {
17821782
resultTypes.removeAll(superTypes);
17831783
}

0 commit comments

Comments
 (0)