1
- package com .fasterxml .jackson .databind . deser ;
1
+ package com .fasterxml .jackson .failing ;
2
2
3
- import com .fasterxml .jackson .annotation .JsonCreator ;
4
- import com .fasterxml .jackson .annotation .JsonGetter ;
5
- import com .fasterxml .jackson .annotation .JsonProperty ;
6
- import com .fasterxml .jackson .core .JsonProcessingException ;
7
- import com .fasterxml .jackson .databind .ObjectMapper ;
8
3
import java .util .Objects ;
9
- import org .junit .Test ;
10
4
11
- import static org .junit .Assert .assertEquals ;
5
+ import com .fasterxml .jackson .annotation .*;
6
+
7
+ import com .fasterxml .jackson .databind .BaseMapTest ;
8
+ import com .fasterxml .jackson .databind .ObjectMapper ;
9
+ import com .fasterxml .jackson .databind .json .JsonMapper ;
12
10
13
- public class MixingFactoryMethodTest {
14
- public static class Timestamped <T > {
11
+ public class MixinForFactoryMethod3220Test
12
+ extends BaseMapTest
13
+ {
14
+ // [databind#3220]
15
+ static class Timestamped <T > {
15
16
private final T value ;
16
17
private final int timestamp ;
17
18
18
- private Timestamped (T value , int timestamp ) {
19
+ Timestamped (T value , int timestamp ) {
19
20
this .value = value ;
20
21
this .timestamp = timestamp ;
21
22
}
@@ -46,12 +47,11 @@ public int hashCode() {
46
47
}
47
48
}
48
49
49
- public abstract static class TimestampedMixin <T > {
50
+ abstract static class TimestampedMixin <T > {
50
51
@ JsonCreator
51
52
public static <T > void stamp (
52
53
@ JsonProperty ("value" ) T value ,
53
- @ JsonProperty ("timestamp" ) int timestamp
54
- ) {
54
+ @ JsonProperty ("timestamp" ) int timestamp ) {
55
55
}
56
56
57
57
@ JsonGetter ("value" )
@@ -61,16 +61,13 @@ public static <T> void stamp(
61
61
abstract int getTimestamp ();
62
62
}
63
63
64
- public static class Profile {
64
+ static class Profile {
65
65
private final String firstName ;
66
66
private final String lastName ;
67
67
68
68
@ JsonCreator
69
- public Profile (
70
- @ JsonProperty ("firstName" )
71
- String firstName ,
72
- @ JsonProperty ("lastName" )
73
- String lastName
69
+ public Profile (@ JsonProperty ("firstName" ) String firstName ,
70
+ @ JsonProperty ("lastName" ) String lastName
74
71
) {
75
72
this .firstName = firstName ;
76
73
this .lastName = lastName ;
@@ -100,14 +97,11 @@ public int hashCode() {
100
97
}
101
98
}
102
99
103
- public static class User {
100
+ static class User {
104
101
private final Timestamped <Profile > profile ;
105
102
106
103
@ JsonCreator
107
- private User (
108
- @ JsonProperty ("profile" )
109
- Timestamped <Profile > profile
110
- ) {
104
+ User (@ JsonProperty ("profile" ) Timestamped <Profile > profile ) {
111
105
this .profile = profile ;
112
106
}
113
107
@@ -130,10 +124,12 @@ public int hashCode() {
130
124
}
131
125
}
132
126
133
- @ Test
134
- public void testMixin () throws JsonProcessingException {
135
- ObjectMapper mapper = new ObjectMapper ();
136
- mapper .addMixIn (Timestamped .class , TimestampedMixin .class );
127
+ // [databind#3220]
128
+ public void testMixin () throws Exception
129
+ {
130
+ ObjectMapper mapper = JsonMapper .builder ()
131
+ .addMixIn (Timestamped .class , TimestampedMixin .class )
132
+ .build ();
137
133
138
134
Profile profile = new Profile ("Jackson" , "Databind" );
139
135
User user = new User (new Timestamped <>(profile , 1 ));
@@ -144,7 +140,6 @@ public void testMixin() throws JsonProcessingException {
144
140
);
145
141
146
142
Profile deserializedProfile = deserializedUser .getProfile ().getValue ();
147
-
148
143
assertEquals (profile , deserializedProfile );
149
144
assertEquals (user , deserializedUser );
150
145
}
0 commit comments