Skip to content

Commit c4ad251

Browse files
committed
Fixed #1016
1 parent 20a67f7 commit c4ad251

File tree

2 files changed

+87
-15
lines changed

2 files changed

+87
-15
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/UUIDDeserializer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.UUID;
66

77
import com.fasterxml.jackson.core.Base64Variants;
8-
import com.fasterxml.jackson.core.JsonParser;
8+
99
import com.fasterxml.jackson.databind.DeserializationContext;
1010
import com.fasterxml.jackson.databind.JsonMappingException;
1111
import com.fasterxml.jackson.databind.exc.InvalidFormatException;

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

+86-14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ public class JacksonAnnotationIntrospector
3232
{
3333
private static final long serialVersionUID = 1L;
3434

35+
private static final Java7Support _jdk7Helper;
36+
static {
37+
Java7Support x = null;
38+
try {
39+
x = Java7Support.class.newInstance();
40+
} catch (Throwable t) {
41+
// 24-Nov-2015, tatu: Should we log or not?
42+
java.util.logging.Logger.getLogger(JacksonAnnotationIntrospector.class.getName())
43+
.warning("Unable to load JDK7 annotation types; will have to skip");
44+
}
45+
_jdk7Helper = x;
46+
}
47+
3548
/**
3649
* Since introspection of annotation types is a performance issue in some
3750
* use cases (rare, but do exist), let's try a simple cache to reduce
@@ -999,11 +1012,11 @@ public boolean hasCreatorAnnotation(Annotated a)
9991012
return (ann.mode() != JsonCreator.Mode.DISABLED);
10001013
}
10011014
if (a instanceof AnnotatedConstructor) {
1002-
ConstructorProperties props = _findAnnotation(a, ConstructorProperties.class);
1003-
// 08-Nov-2015, tatu: One possible check would be to ensure there is at least
1004-
// one name iff constructor has arguments. But seems unnecessary for now.
1005-
if (props != null) {
1006-
return true;
1015+
if (_jdk7Helper != null) {
1016+
Boolean b = _jdk7Helper.hasCreatorAnnotation(a);
1017+
if (b != null) {
1018+
return b.booleanValue();
1019+
}
10071020
}
10081021
}
10091022
return false;
@@ -1027,9 +1040,11 @@ protected boolean _isIgnorable(Annotated a)
10271040
if (ann != null) {
10281041
return ann.value();
10291042
}
1030-
Transient t = _findAnnotation(a, Transient.class);
1031-
if (t != null) {
1032-
return t.value();
1043+
if (_jdk7Helper != null) {
1044+
Boolean b = _jdk7Helper.findTransient(a);
1045+
if (b != null) {
1046+
return b.booleanValue();
1047+
}
10331048
}
10341049
return false;
10351050
}
@@ -1063,12 +1078,10 @@ protected PropertyName _findConstructorName(Annotated a)
10631078
AnnotatedWithParams ctor = p.getOwner();
10641079

10651080
if (ctor != null) {
1066-
ConstructorProperties props = _findAnnotation(ctor, ConstructorProperties.class);
1067-
if (props != null) {
1068-
String[] names = props.value();
1069-
int ix = p.getIndex();
1070-
if (ix < names.length) {
1071-
return PropertyName.construct(names[ix]);
1081+
if (_jdk7Helper != null) {
1082+
PropertyName name = _jdk7Helper.findConstructorName(p);
1083+
if (name != null) {
1084+
return name;
10721085
}
10731086
}
10741087
}
@@ -1154,4 +1167,63 @@ protected StdTypeResolverBuilder _constructStdTypeResolverBuilder() {
11541167
protected StdTypeResolverBuilder _constructNoTypeResolverBuilder() {
11551168
return StdTypeResolverBuilder.noTypeInfoBuilder();
11561169
}
1170+
1171+
/*
1172+
/**********************************************************
1173+
/* Helper classes
1174+
/**********************************************************
1175+
*/
1176+
1177+
/**
1178+
* To support Java7-incomplete platforms, we will offer support for JDK 7
1179+
* annotations through this class, loaded dynamically; if loading fails,
1180+
* support will be missing.
1181+
*/
1182+
private static class Java7Support
1183+
{
1184+
@SuppressWarnings("unused") // compiler warns, just needed side-effects
1185+
private final Class<?> _bogus;
1186+
1187+
@SuppressWarnings("unused") // compiler warns; called via Reflection
1188+
public Java7Support() {
1189+
// Trigger loading of annotations that only JDK 7 has...
1190+
Class<?> cls = Transient.class;
1191+
cls = ConstructorProperties.class;
1192+
_bogus = cls;
1193+
}
1194+
1195+
public Boolean findTransient(Annotated a) {
1196+
Transient t = a.getAnnotation(Transient.class);
1197+
if (t != null) {
1198+
return t.value();
1199+
}
1200+
return null;
1201+
}
1202+
1203+
public Boolean hasCreatorAnnotation(Annotated a) {
1204+
ConstructorProperties props = a.getAnnotation(ConstructorProperties.class);
1205+
// 08-Nov-2015, tatu: One possible check would be to ensure there is at least
1206+
// one name iff constructor has arguments. But seems unnecessary for now.
1207+
if (props != null) {
1208+
return Boolean.TRUE;
1209+
}
1210+
return null;
1211+
}
1212+
1213+
public PropertyName findConstructorName(AnnotatedParameter p)
1214+
{
1215+
AnnotatedWithParams ctor = p.getOwner();
1216+
if (ctor != null) {
1217+
ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class);
1218+
if (props != null) {
1219+
String[] names = props.value();
1220+
int ix = p.getIndex();
1221+
if (ix < names.length) {
1222+
return PropertyName.construct(names[ix]);
1223+
}
1224+
}
1225+
}
1226+
return null;
1227+
}
1228+
}
11571229
}

0 commit comments

Comments
 (0)