Skip to content

Commit 2f76bc8

Browse files
committed
start working on supporting @JsonValue on fields
1 parent 958a60c commit 2f76bc8

File tree

4 files changed

+56
-19
lines changed

4 files changed

+56
-19
lines changed

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

+21-3
Original file line numberDiff line numberDiff line change
@@ -856,13 +856,31 @@ public PropertyName findNameForSerialization(Annotated a) {
856856
* should be used as "the value" of the object instance; usually
857857
* serialized as a primitive value such as String or number.
858858
*
859-
* @return True if such annotation is found (and is not disabled);
860-
* false if no enabled annotation is found
859+
* @return {@link Boolean#TRUE} if such annotation is found and is not disabled;
860+
* {@link Boolean#FALSE} if disabled annotation (block) is found (to indicate
861+
* accessor is definitely NOT to be used "as value"); or `null` if no
862+
* information found.
863+
*
864+
* @since 2.9
861865
*/
866+
public Boolean findAsValueAnnotation(Annotated a) {
867+
// 20-Nov-2016, tatu: Delegate in 2.9; remove redirect from later versions
868+
if (a instanceof AnnotatedMethod) {
869+
if (hasAsValueAnnotation((AnnotatedMethod) a)) {
870+
return true;
871+
}
872+
}
873+
return null;
874+
}
875+
876+
/**
877+
* @deprecated Since 2.9 Use {@link #findAsValueAnnotation(Annotated)} instead.
878+
*/
879+
@Deprecated // since 2.9
862880
public boolean hasAsValueAnnotation(AnnotatedMethod am) {
863881
return false;
864882
}
865-
883+
866884
/**
867885
* Method for checking whether given method has an annotation
868886
* that suggests that the method is to serve as "any setter";

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

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

77
import com.fasterxml.jackson.core.JsonParser;
8-
import com.fasterxml.jackson.core.JsonToken;
98
import com.fasterxml.jackson.databind.*;
109
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
1110
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;

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

+21-11
Original file line numberDiff line numberDiff line change
@@ -563,23 +563,20 @@ public PropertyName findNameForSerialization(Annotated a) {
563563
}
564564
return n;
565565
}
566-
566+
567567
@Override
568-
public boolean hasAsValueAnnotation(AnnotatedMethod am) {
569-
return _primary.hasAsValueAnnotation(am) || _secondary.hasAsValueAnnotation(am);
568+
public Boolean findAsValueAnnotation(Annotated a) {
569+
Boolean b = _primary.findAsValueAnnotation(a);
570+
if (b == null) {
571+
b = _secondary.findAsValueAnnotation(a);
572+
}
573+
return b;
570574
}
571-
575+
572576
@Override
573577
public boolean hasAnyGetterAnnotation(AnnotatedMethod am) {
574578
return _primary.hasAnyGetterAnnotation(am) || _secondary.hasAnyGetterAnnotation(am);
575579
}
576-
577-
@Override
578-
@Deprecated
579-
public String findEnumValue(Enum<?> value) {
580-
String r = _primary.findEnumValue(value);
581-
return (r == null) ? _secondary.findEnumValue(value) : r;
582-
}
583580

584581
@Override
585582
public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] names) {
@@ -595,6 +592,19 @@ public Enum<?> findDefaultEnumValue(Class<Enum<?>> enumCls) {
595592
return (en == null) ? _secondary.findDefaultEnumValue(enumCls) : en;
596593
}
597594

595+
@Override
596+
@Deprecated // since 2.8
597+
public String findEnumValue(Enum<?> value) {
598+
String r = _primary.findEnumValue(value);
599+
return (r == null) ? _secondary.findEnumValue(value) : r;
600+
}
601+
602+
@Override
603+
@Deprecated // since 2.9
604+
public boolean hasAsValueAnnotation(AnnotatedMethod am) {
605+
return _primary.hasAsValueAnnotation(am) || _secondary.hasAsValueAnnotation(am);
606+
}
607+
598608
// // // Deserialization: general annotations
599609

600610
@Override

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,12 @@ public PropertyName findNameForSerialization(Annotated a)
973973
}
974974

975975
@Override
976-
public boolean hasAsValueAnnotation(AnnotatedMethod am) {
977-
JsonValue ann = _findAnnotation(am, JsonValue.class);
978-
// value of 'false' means disabled...
979-
return (ann != null && ann.value());
976+
public Boolean findAsValueAnnotation(Annotated a) {
977+
JsonValue ann = _findAnnotation(a, JsonValue.class);
978+
if (ann == null) {
979+
return null;
980+
}
981+
return ann.value();
980982
}
981983

982984
@Override
@@ -986,6 +988,14 @@ public boolean hasAnyGetterAnnotation(AnnotatedMethod am)
986988
return _hasAnnotation(am, JsonAnyGetter.class);
987989
}
988990

991+
@Override
992+
@Deprecated // since 2.9
993+
public boolean hasAsValueAnnotation(AnnotatedMethod am) {
994+
JsonValue ann = _findAnnotation(am, JsonValue.class);
995+
// value of 'false' means disabled...
996+
return (ann != null) && ann.value();
997+
}
998+
989999
/*
9901000
/**********************************************************
9911001
/* Deserialization: general annotations

0 commit comments

Comments
 (0)