Skip to content

Commit 24e2968

Browse files
committed
Added test case for when PropertyNamingStrategy is specified
1 parent e99ea39 commit 24e2968

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,27 @@ class TestJacksonWithKotlin {
2525
val primaryAddress: String
2626
val wrongName: Boolean
2727
val createdDt: Date
28+
val isName: Boolean
2829

2930
fun validate(
3031
nameField: String = name,
3132
ageField: Int = age,
3233
addressField: String = primaryAddress,
3334
wrongNameField: Boolean = wrongName,
34-
createDtField: Date = createdDt
35+
createDtField: Date = createdDt,
36+
isNameField: Boolean = isName,
3537
) {
3638
assertThat(nameField, equalTo("Frank"))
3739
assertThat(ageField, equalTo(30))
3840
assertThat(addressField, equalTo("something here"))
3941
assertThat(wrongNameField, equalTo(true))
4042
assertThat(createDtField, equalTo(Date(1477419948000)))
43+
assertThat(isNameField, equalTo(false))
4144
}
4245
}
4346

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}"""
4649

4750
private val normalCasedMapper = jacksonObjectMapper()
4851
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
@@ -65,6 +68,7 @@ class TestJacksonWithKotlin {
6568

6669
override var primaryAddress: String = ""
6770
override var createdDt: Date = Date()
71+
override val isName: Boolean = false
6872
}
6973

7074
@Test fun NoFailWithDefaultAndSpecificConstructor() {
@@ -79,7 +83,8 @@ class TestJacksonWithKotlin {
7983
override val age: Int,
8084
override val primaryAddress: String,
8185
val renamed: Boolean,
82-
override val createdDt: Date
86+
override val createdDt: Date,
87+
override val isName: Boolean
8388
) : TestFields {
8489
@JsonIgnore
8590
override val wrongName = renamed // here for the test validation only
@@ -97,7 +102,8 @@ class TestJacksonWithKotlin {
97102
override val age: Int,
98103
override val primaryAddress: String,
99104
val renamed: Boolean,
100-
override val createdDt: Date
105+
override val createdDt: Date,
106+
override val isName: Boolean
101107
) : TestFields {
102108
@JsonIgnore
103109
override val wrongName = renamed // here for the test validation only
@@ -121,7 +127,8 @@ class TestJacksonWithKotlin {
121127
override val age: Int,
122128
override val primaryAddress: String,
123129
@JsonProperty("renamed") override val wrongName: Boolean,
124-
override val createdDt: Date
130+
override val createdDt: Date,
131+
override val isName: Boolean
125132
) : TestFields
126133

127134
@Test fun testDataClassWithExplicitJsonCreatorAndJsonProperty() {
@@ -141,7 +148,8 @@ class TestJacksonWithKotlin {
141148
override val age: Int,
142149
override val primaryAddress: String,
143150
@JsonProperty("renamed") override val wrongName: Boolean,
144-
override val createdDt: Date
151+
override val createdDt: Date,
152+
override val isName: Boolean
145153
) : TestFields
146154

147155
@Test fun testNormalClassWithJsonCreator() {
@@ -155,7 +163,8 @@ class TestJacksonWithKotlin {
155163
private class StateObjectWithPartialFieldsInConstructor(
156164
override val name: String,
157165
override val age: Int,
158-
override val primaryAddress: String
166+
override val primaryAddress: String,
167+
override val isName: Boolean
159168
) : TestFields {
160169
@JsonProperty("renamed") override var wrongName: Boolean = false
161170
override var createdDt: Date by Delegates.notNull()
@@ -176,7 +185,8 @@ class TestJacksonWithKotlin {
176185
override val age: Int,
177186
override val primaryAddress: String,
178187
@JsonProperty("renamed") override val wrongName: Boolean,
179-
override val createdDt: Date
188+
override val createdDt: Date,
189+
override val isName: Boolean
180190
) : TestFields
181191

182192
@Test fun testDataClassWithNonFieldParametersInConstructor() {
@@ -207,7 +217,8 @@ class TestJacksonWithKotlin {
207217
override val age: Int,
208218
override val primaryAddress: String,
209219
override val wrongName: Boolean,
210-
override val createdDt: Date
220+
override val createdDt: Date,
221+
override val isName: Boolean
211222
) : TestFields {
212223
var factoryUsed: Boolean = false
213224
companion object {
@@ -216,9 +227,10 @@ class TestJacksonWithKotlin {
216227
@JsonProperty("age") age: Int,
217228
@JsonProperty("primaryAddress") primaryAddress: String,
218229
@JsonProperty("renamed") wrongName: Boolean,
219-
@JsonProperty("createdDt") createdDt: Date
230+
@JsonProperty("createdDt") createdDt: Date,
231+
@JsonProperty("isName") isName: Boolean
220232
): StateObjectWithFactory {
221-
val obj = StateObjectWithFactory(nameThing, age, primaryAddress, wrongName, createdDt)
233+
val obj = StateObjectWithFactory(nameThing, age, primaryAddress, wrongName, createdDt, isName)
222234
obj.factoryUsed = true
223235
return obj
224236
}
@@ -236,17 +248,19 @@ class TestJacksonWithKotlin {
236248
val age: Int,
237249
val primaryAddress: String,
238250
val renamed: Boolean,
239-
val createdDt: Date
251+
val createdDt: Date,
252+
val isName: Boolean
240253
) {
241254
companion object {
242255
@JvmStatic @JsonCreator fun create(
243256
name: String,
244257
age: Int,
245258
primaryAddress: String,
246259
renamed: Boolean,
247-
createdDt: Date
260+
createdDt: Date,
261+
isName: Boolean
248262
): StateObjectWithFactoryNoParamAnnotations {
249-
return StateObjectWithFactoryNoParamAnnotations(name, age, primaryAddress, renamed, createdDt)
263+
return StateObjectWithFactoryNoParamAnnotations(name, age, primaryAddress, renamed, createdDt, isName)
250264
}
251265
}
252266
}
@@ -266,7 +280,8 @@ class TestJacksonWithKotlin {
266280
override val age: Int,
267281
override val primaryAddress: String,
268282
override val wrongName: Boolean,
269-
override val createdDt: Date
283+
override val createdDt: Date,
284+
override val isName: Boolean
270285
) : TestFields {
271286
var factoryUsed: Boolean = false
272287
private companion object Named {
@@ -275,9 +290,10 @@ class TestJacksonWithKotlin {
275290
@JsonProperty("age") age: Int,
276291
@JsonProperty("primaryAddress") primaryAddress: String,
277292
@JsonProperty("renamed") wrongName: Boolean,
278-
@JsonProperty("createdDt") createdDt: Date
293+
@JsonProperty("createdDt") createdDt: Date,
294+
@JsonProperty("isName") isName: Boolean
279295
): StateObjectWithFactoryOnNamedCompanion {
280-
val obj = StateObjectWithFactoryOnNamedCompanion(nameThing, age, primaryAddress, wrongName, createdDt)
296+
val obj = StateObjectWithFactoryOnNamedCompanion(nameThing, age, primaryAddress, wrongName, createdDt, isName)
281297
obj.factoryUsed = true
282298
return obj
283299
}

0 commit comments

Comments
 (0)