Skip to content

Commit f04fb75

Browse files
Migrate legacy reflection properties to use MethodHandles, attempt #2
Fixes #2083
1 parent ceab973 commit f04fb75

12 files changed

+339
-433
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
@@ -610,7 +610,7 @@ public SettableBeanProperty unwrapped(DeserializationContext ctxt, NameTransform
610610
/**********************************************************************
611611
*/
612612

613-
protected void _throwAsJacksonE(JsonParser p, Exception e, Object value)
613+
protected void _throwAsJacksonE(JsonParser p, Throwable e, Object value)
614614
throws JacksonException
615615
{
616616
if (e instanceof IllegalArgumentException) {
@@ -633,8 +633,9 @@ protected void _throwAsJacksonE(JsonParser p, Exception e, Object value)
633633
_throwAsJacksonE(p, e);
634634
}
635635

636-
protected void _throwAsJacksonE(JsonParser p, Exception e) throws JacksonException
636+
protected void _throwAsJacksonE(JsonParser p, Throwable e) throws JacksonException
637637
{
638+
ClassUtil.throwIfError(e);
638639
ClassUtil.throwIfRTE(e);
639640
ClassUtil.throwIfJacksonE(e);
640641

@@ -653,7 +654,7 @@ protected void _throwAsJacksonE(JsonParser p, Exception e) throws JacksonExcepti
653654

654655
// 10-Oct-2015, tatu: _Should_ be deprecated, too, but its remaining
655656
// callers cannot actually provide a JsonParser
656-
protected void _throwAsJacksonE(Exception e, Object value) throws JacksonException {
657+
protected void _throwAsJacksonE(Throwable e, Object value) throws JacksonException {
657658
_throwAsJacksonE((JsonParser) null, e, value);
658659
}
659660

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

-227
This file was deleted.

0 commit comments

Comments
 (0)