1
1
package com .fasterxml .jackson .databind .deser .impl ;
2
2
3
3
import java .io .IOException ;
4
- import java .lang .annotation .Annotation ;
5
4
6
5
import com .fasterxml .jackson .core .JsonParser ;
7
6
import com .fasterxml .jackson .databind .DeserializationContext ;
8
- import com .fasterxml .jackson .databind .JsonDeserializer ;
9
- import com .fasterxml .jackson .databind .PropertyName ;
10
7
import com .fasterxml .jackson .databind .deser .*;
11
8
import com .fasterxml .jackson .databind .introspect .AnnotatedMember ;
12
9
19
16
* @since 2.9
20
17
*/
21
18
public class MergingSettableBeanProperty
22
- extends SettableBeanProperty
19
+ extends SettableBeanProperty . Delegating
23
20
{
24
21
private static final long serialVersionUID = 1L ;
25
22
26
23
/**
27
- * Underlying actual property (field- or member-backed) .
24
+ * Member (field, method) used for accessing existing value .
28
25
*/
29
- protected final SettableBeanProperty _delegate ;
26
+ protected final AnnotatedMember _accessor ;
30
27
31
28
/*
32
29
/**********************************************************
33
30
/* Life-cycle
34
31
/**********************************************************
35
32
*/
36
33
37
- public MergingSettableBeanProperty (SettableBeanProperty delegate )
34
+ protected MergingSettableBeanProperty (SettableBeanProperty delegate ,
35
+ AnnotatedMember accessor )
38
36
{
39
37
super (delegate );
40
- _delegate = delegate ;
38
+ _accessor = accessor ;
41
39
}
42
40
43
41
protected MergingSettableBeanProperty (MergingSettableBeanProperty src ,
44
42
SettableBeanProperty delegate )
45
43
{
46
- super (src );
47
- _delegate = src ._delegate ;
48
- }
49
-
50
- @ Override
51
- public SettableBeanProperty withValueDeserializer (JsonDeserializer <?> deser ) {
52
- return _new (_delegate .withValueDeserializer (deser ));
53
- }
54
-
55
- @ Override
56
- public SettableBeanProperty withName (PropertyName newName ) {
57
- return _new (_delegate .withName (newName ));
58
- }
59
-
60
- protected MergingSettableBeanProperty _new (SettableBeanProperty newDelegate ) {
61
- if (newDelegate == _delegate ) {
62
- return this ;
63
- }
64
- return new MergingSettableBeanProperty (this , newDelegate );
44
+ super (delegate );
45
+ _accessor = src ._accessor ;
65
46
}
66
47
67
- /*
68
- /**********************************************************
69
- /* BeanProperty impl
70
- /**********************************************************
71
- */
72
-
73
- @ Override
74
- public AnnotatedMember getMember () {
75
- return _delegate .getMember ();
48
+ public static MergingSettableBeanProperty construct (SettableBeanProperty delegate ,
49
+ AnnotatedMember accessor )
50
+ {
51
+ return new MergingSettableBeanProperty (delegate , accessor );
76
52
}
77
53
78
54
@ Override
79
- public < A extends Annotation > A getAnnotation ( Class < A > acls ) {
80
- return _delegate . getAnnotation ( acls );
55
+ protected SettableBeanProperty withDelegate ( SettableBeanProperty d ) {
56
+ return new MergingSettableBeanProperty ( d , _accessor );
81
57
}
82
58
83
59
/*
@@ -90,25 +66,39 @@ public <A extends Annotation> A getAnnotation(Class<A> acls) {
90
66
public void deserializeAndSet (JsonParser p , DeserializationContext ctxt ,
91
67
Object instance ) throws IOException
92
68
{
93
- // TODO Auto-generated method stub
69
+ delegate . set ( instance , _deserialize ( p , ctxt , instance ));
94
70
}
95
71
96
72
@ Override
97
73
public Object deserializeSetAndReturn (JsonParser p ,
98
74
DeserializationContext ctxt , Object instance ) throws IOException {
99
- // TODO Auto-generated method stub
100
- return null ;
75
+ return delegate .setAndReturn (instance , _deserialize (p , ctxt , instance ));
101
76
}
102
77
103
78
@ Override
104
79
public void set (Object instance , Object value ) throws IOException {
105
- // TODO Auto-generated method stub
80
+ delegate . set ( instance , value );
106
81
}
107
82
108
83
@ Override
109
84
public Object setAndReturn (Object instance , Object value )
110
- throws IOException {
111
- // TODO Auto-generated method stub
112
- return null ;
85
+ throws IOException
86
+ {
87
+ return delegate .setAndReturn (instance , value );
88
+ }
89
+
90
+ protected Object _deserialize (JsonParser p , DeserializationContext ctxt ,
91
+ Object instance ) throws IOException
92
+ {
93
+ Object value = _accessor .getValue (instance );
94
+ // 20-Oct-2016, tatu: Couple of possibilities of how to proceed; for
95
+ // now, default to "normal" handling without merging
96
+ if (value == null ) {
97
+ return delegate .deserialize (p , ctxt );
98
+ }
99
+ Object result = delegate .deserializeWith (p , ctxt , value );
100
+ // 20-Oct-2016, tatu: Similarly, we may get same object or different one;
101
+ // whether to return original or new is an open question.
102
+ return result ;
113
103
}
114
104
}
0 commit comments