@@ -25,24 +25,27 @@ class TestJacksonWithKotlin {
25
25
val primaryAddress: String
26
26
val wrongName: Boolean
27
27
val createdDt: Date
28
+ val isName: Boolean
28
29
29
30
fun validate (
30
31
nameField : String = name,
31
32
ageField : Int = age,
32
33
addressField : String = primaryAddress,
33
34
wrongNameField : Boolean = wrongName,
34
- createDtField : Date = createdDt
35
+ createDtField : Date = createdDt,
36
+ isNameField : Boolean = isName,
35
37
) {
36
38
assertThat(nameField, equalTo(" Frank" ))
37
39
assertThat(ageField, equalTo(30 ))
38
40
assertThat(addressField, equalTo(" something here" ))
39
41
assertThat(wrongNameField, equalTo(true ))
40
42
assertThat(createDtField, equalTo(Date (1477419948000 )))
43
+ assertThat(isNameField, equalTo(false ))
41
44
}
42
45
}
43
46
44
- private val normalCasedJson = """ {"name":"Frank","age":30,"primaryAddress":"something here","renamed":true,"createdDt":"2016-10-25T18:25:48.000+00:00"}"""
45
- private val pascalCasedJson = """ {"Name":"Frank","Age":30,"PrimaryAddress":"something here","Renamed":true,"CreatedDt":"2016-10-25T18:25:48.000+00:00"}"""
47
+ private val normalCasedJson = """ {"name":"Frank","age":30,"primaryAddress":"something here","renamed":true,"createdDt":"2016-10-25T18:25:48.000+00:00","isName":false }"""
48
+ private val pascalCasedJson = """ {"Name":"Frank","Age":30,"PrimaryAddress":"something here","Renamed":true,"CreatedDt":"2016-10-25T18:25:48.000+00:00","IsName":false }"""
46
49
47
50
private val normalCasedMapper = jacksonObjectMapper()
48
51
.configure(SerializationFeature .WRITE_DATES_AS_TIMESTAMPS , false )
@@ -65,6 +68,7 @@ class TestJacksonWithKotlin {
65
68
66
69
override var primaryAddress: String = " "
67
70
override var createdDt: Date = Date ()
71
+ override val isName: Boolean = false
68
72
}
69
73
70
74
@Test fun NoFailWithDefaultAndSpecificConstructor () {
@@ -79,7 +83,8 @@ class TestJacksonWithKotlin {
79
83
override val age : Int ,
80
84
override val primaryAddress : String ,
81
85
val renamed : Boolean ,
82
- override val createdDt : Date
86
+ override val createdDt : Date ,
87
+ override val isName : Boolean
83
88
) : TestFields {
84
89
@JsonIgnore
85
90
override val wrongName = renamed // here for the test validation only
@@ -97,7 +102,8 @@ class TestJacksonWithKotlin {
97
102
override val age : Int ,
98
103
override val primaryAddress : String ,
99
104
val renamed : Boolean ,
100
- override val createdDt : Date
105
+ override val createdDt : Date ,
106
+ override val isName : Boolean
101
107
) : TestFields {
102
108
@JsonIgnore
103
109
override val wrongName = renamed // here for the test validation only
@@ -121,7 +127,8 @@ class TestJacksonWithKotlin {
121
127
override val age : Int ,
122
128
override val primaryAddress : String ,
123
129
@JsonProperty(" renamed" ) override val wrongName : Boolean ,
124
- override val createdDt : Date
130
+ override val createdDt : Date ,
131
+ override val isName : Boolean
125
132
) : TestFields
126
133
127
134
@Test fun testDataClassWithExplicitJsonCreatorAndJsonProperty () {
@@ -141,7 +148,8 @@ class TestJacksonWithKotlin {
141
148
override val age : Int ,
142
149
override val primaryAddress : String ,
143
150
@JsonProperty(" renamed" ) override val wrongName : Boolean ,
144
- override val createdDt : Date
151
+ override val createdDt : Date ,
152
+ override val isName : Boolean
145
153
) : TestFields
146
154
147
155
@Test fun testNormalClassWithJsonCreator () {
@@ -155,7 +163,8 @@ class TestJacksonWithKotlin {
155
163
private class StateObjectWithPartialFieldsInConstructor (
156
164
override val name : String ,
157
165
override val age : Int ,
158
- override val primaryAddress : String
166
+ override val primaryAddress : String ,
167
+ override val isName : Boolean
159
168
) : TestFields {
160
169
@JsonProperty(" renamed" ) override var wrongName: Boolean = false
161
170
override var createdDt: Date by Delegates .notNull()
@@ -176,7 +185,8 @@ class TestJacksonWithKotlin {
176
185
override val age : Int ,
177
186
override val primaryAddress : String ,
178
187
@JsonProperty(" renamed" ) override val wrongName : Boolean ,
179
- override val createdDt : Date
188
+ override val createdDt : Date ,
189
+ override val isName : Boolean
180
190
) : TestFields
181
191
182
192
@Test fun testDataClassWithNonFieldParametersInConstructor () {
@@ -207,7 +217,8 @@ class TestJacksonWithKotlin {
207
217
override val age : Int ,
208
218
override val primaryAddress : String ,
209
219
override val wrongName : Boolean ,
210
- override val createdDt : Date
220
+ override val createdDt : Date ,
221
+ override val isName : Boolean
211
222
) : TestFields {
212
223
var factoryUsed: Boolean = false
213
224
companion object {
@@ -216,9 +227,10 @@ class TestJacksonWithKotlin {
216
227
@JsonProperty(" age" ) age : Int ,
217
228
@JsonProperty(" primaryAddress" ) primaryAddress : String ,
218
229
@JsonProperty(" renamed" ) wrongName : Boolean ,
219
- @JsonProperty(" createdDt" ) createdDt : Date
230
+ @JsonProperty(" createdDt" ) createdDt : Date ,
231
+ @JsonProperty(" isName" ) isName : Boolean
220
232
): StateObjectWithFactory {
221
- val obj = StateObjectWithFactory (nameThing, age, primaryAddress, wrongName, createdDt)
233
+ val obj = StateObjectWithFactory (nameThing, age, primaryAddress, wrongName, createdDt, isName )
222
234
obj.factoryUsed = true
223
235
return obj
224
236
}
@@ -236,17 +248,19 @@ class TestJacksonWithKotlin {
236
248
val age : Int ,
237
249
val primaryAddress : String ,
238
250
val renamed : Boolean ,
239
- val createdDt : Date
251
+ val createdDt : Date ,
252
+ val isName : Boolean
240
253
) {
241
254
companion object {
242
255
@JvmStatic @JsonCreator fun create (
243
256
name : String ,
244
257
age : Int ,
245
258
primaryAddress : String ,
246
259
renamed : Boolean ,
247
- createdDt : Date
260
+ createdDt : Date ,
261
+ isName : Boolean
248
262
): StateObjectWithFactoryNoParamAnnotations {
249
- return StateObjectWithFactoryNoParamAnnotations (name, age, primaryAddress, renamed, createdDt)
263
+ return StateObjectWithFactoryNoParamAnnotations (name, age, primaryAddress, renamed, createdDt, isName )
250
264
}
251
265
}
252
266
}
@@ -266,7 +280,8 @@ class TestJacksonWithKotlin {
266
280
override val age : Int ,
267
281
override val primaryAddress : String ,
268
282
override val wrongName : Boolean ,
269
- override val createdDt : Date
283
+ override val createdDt : Date ,
284
+ override val isName : Boolean
270
285
) : TestFields {
271
286
var factoryUsed: Boolean = false
272
287
private companion object Named {
@@ -275,9 +290,10 @@ class TestJacksonWithKotlin {
275
290
@JsonProperty(" age" ) age : Int ,
276
291
@JsonProperty(" primaryAddress" ) primaryAddress : String ,
277
292
@JsonProperty(" renamed" ) wrongName : Boolean ,
278
- @JsonProperty(" createdDt" ) createdDt : Date
293
+ @JsonProperty(" createdDt" ) createdDt : Date ,
294
+ @JsonProperty(" isName" ) isName : Boolean
279
295
): StateObjectWithFactoryOnNamedCompanion {
280
- val obj = StateObjectWithFactoryOnNamedCompanion (nameThing, age, primaryAddress, wrongName, createdDt)
296
+ val obj = StateObjectWithFactoryOnNamedCompanion (nameThing, age, primaryAddress, wrongName, createdDt, isName )
281
297
obj.factoryUsed = true
282
298
return obj
283
299
}
0 commit comments