Skip to content

Commit 5309694

Browse files
Migrate legacy reflection properties to use MethodHandles, attempt #2
Fixes #2083
1 parent 53fed21 commit 5309694

12 files changed

+342
-435
lines changed

src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tools.jackson.databind.deser;
22

3+
import java.lang.reflect.Modifier;
34
import java.util.*;
45

56
import com.fasterxml.jackson.annotation.*;
@@ -935,14 +936,10 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
935936
// Does the Method specify the deserializer to use? If so, let's use it.
936937
TypeDeserializer typeDeser = (TypeDeserializer) type.getTypeHandler();
937938
SettableBeanProperty prop;
938-
if (mutator instanceof AnnotatedMethod) {
939-
prop = new MethodProperty(propDef, type, typeDeser,
940-
beanDesc.getClassAnnotations(), (AnnotatedMethod) mutator);
941-
} else {
942-
// 08-Sep-2016, tatu: wonder if we should verify it is `AnnotatedField` to be safe?
943-
prop = new FieldProperty(propDef, type, typeDeser,
944-
beanDesc.getClassAnnotations(), (AnnotatedField) mutator);
939+
if (isFinalField(mutator)) {
940+
return null;
945941
}
942+
prop = new MethodProperty(propDef, type, typeDeser, beanDesc.getClassAnnotations(), mutator);
946943
ValueDeserializer<?> deser = findDeserializerFromAnnotation(ctxt, mutator);
947944
if (deser == null) {
948945
deser = (ValueDeserializer<?>) type.getValueHandler();
@@ -963,6 +960,11 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
963960
return prop;
964961
}
965962

963+
private boolean isFinalField(AnnotatedMember am) {
964+
return am instanceof AnnotatedField
965+
&& Modifier.isFinal(am.getMember().getModifiers());
966+
}
967+
966968
/**
967969
* Method that will construct a regular bean property setter using
968970
* the given setter method.

src/main/java/tools/jackson/databind/deser/SettableBeanProperty.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ public SettableBeanProperty unwrapped(DeserializationContext ctxt, NameTransform
609609
/**********************************************************************
610610
*/
611611

612-
protected void _throwAsJacksonE(JsonParser p, Exception e, Object value)
612+
protected void _throwAsJacksonE(JsonParser p, Throwable e, Object value)
613613
throws JacksonException
614614
{
615615
if (e instanceof IllegalArgumentException) {
@@ -632,8 +632,9 @@ protected void _throwAsJacksonE(JsonParser p, Exception e, Object value)
632632
_throwAsJacksonE(p, e);
633633
}
634634

635-
protected void _throwAsJacksonE(JsonParser p, Exception e) throws JacksonException
635+
protected void _throwAsJacksonE(JsonParser p, Throwable e) throws JacksonException
636636
{
637+
ClassUtil.throwIfError(e);
637638
ClassUtil.throwIfRTE(e);
638639
ClassUtil.throwIfJacksonE(e);
639640
// let's wrap the innermost problem
@@ -643,7 +644,7 @@ protected void _throwAsJacksonE(JsonParser p, Exception e) throws JacksonExcepti
643644

644645
// 10-Oct-2015, tatu: _Should_ be deprecated, too, but its remaining
645646
// callers cannot actually provide a JsonParser
646-
protected void _throwAsJacksonE(Exception e, Object value) throws JacksonException {
647+
protected void _throwAsJacksonE(Throwable e, Object value) throws JacksonException {
647648
_throwAsJacksonE((JsonParser) null, e, value);
648649
}
649650

src/main/java/tools/jackson/databind/deser/impl/FieldProperty.java

-227
This file was deleted.

0 commit comments

Comments
 (0)