@@ -26,7 +26,13 @@ class TestJacksonWithKotlin {
2626 val wrongName: Boolean
2727 val createdDt: Date
2828
29- fun validate (nameField : String = name, ageField : Int = age, addressField : String = primaryAddress, wrongNameField : Boolean = wrongName, createDtField : Date = createdDt) {
29+ fun validate (
30+ nameField : String = name,
31+ ageField : Int = age,
32+ addressField : String = primaryAddress,
33+ wrongNameField : Boolean = wrongName,
34+ createDtField : Date = createdDt
35+ ) {
3036 assertThat(nameField, equalTo(" Frank" ))
3137 assertThat(ageField, equalTo(30 ))
3238 assertThat(addressField, equalTo(" something here" ))
@@ -50,7 +56,10 @@ class TestJacksonWithKotlin {
5056
5157 // ==================
5258
53- private class DefaultAndSpecificConstructor (override var name : String = " " , override var age : Int = 0 ) : TestFields {
59+ private class DefaultAndSpecificConstructor (
60+ override var name : String = " " ,
61+ override var age : Int = 0
62+ ) : TestFields {
5463 @JsonProperty(" renamed" )
5564 override var wrongName: Boolean = false
5665
@@ -65,7 +74,13 @@ class TestJacksonWithKotlin {
6574
6675 // ==================
6776
68- private class NoFailWithoutJsonCreator (override val name : String , override val age : Int , override val primaryAddress : String , val renamed : Boolean , override val createdDt : Date ) : TestFields {
77+ private class NoFailWithoutJsonCreator (
78+ override val name : String ,
79+ override val age : Int ,
80+ override val primaryAddress : String ,
81+ val renamed : Boolean ,
82+ override val createdDt : Date
83+ ) : TestFields {
6984 @JsonIgnore
7085 override val wrongName = renamed // here for the test validation only
7186 }
@@ -77,7 +92,13 @@ class TestJacksonWithKotlin {
7792
7893 // ==================
7994
80- private data class StateObjectAsDataClassExplicitJsonCreator @JsonCreator constructor(override val name : String , override val age : Int , override val primaryAddress : String , val renamed : Boolean , override val createdDt : Date ) : TestFields {
95+ private data class StateObjectAsDataClassExplicitJsonCreator @JsonCreator constructor(
96+ override val name : String ,
97+ override val age : Int ,
98+ override val primaryAddress : String ,
99+ val renamed : Boolean ,
100+ override val createdDt : Date
101+ ) : TestFields {
81102 @JsonIgnore
82103 override val wrongName = renamed // here for the test validation only
83104 }
@@ -95,11 +116,18 @@ class TestJacksonWithKotlin {
95116
96117 // ==================
97118
98- private data class StateObjectAsDataClassWithJsonCreatorAndJsonProperty @JsonCreator constructor(override val name : String , override val age : Int , override val primaryAddress : String , @JsonProperty(" renamed" ) override val wrongName : Boolean , override val createdDt : Date ) : TestFields
119+ private data class StateObjectAsDataClassWithJsonCreatorAndJsonProperty @JsonCreator constructor(
120+ override val name : String ,
121+ override val age : Int ,
122+ override val primaryAddress : String ,
123+ @JsonProperty(" renamed" ) override val wrongName : Boolean ,
124+ override val createdDt : Date
125+ ) : TestFields
99126
100127 @Test fun testDataClassWithExplicitJsonCreatorAndJsonProperty () {
101128 // data class with JsonCreator and JsonProperty
102- val stateObj = normalCasedMapper.readValue<StateObjectAsDataClassWithJsonCreatorAndJsonProperty >(normalCasedJson)
129+ val stateObj = normalCasedMapper
130+ .readValue<StateObjectAsDataClassWithJsonCreatorAndJsonProperty >(normalCasedJson)
103131 stateObj.validate()
104132
105133 val test1out = normalCasedMapper.writeValueAsString(stateObj)
@@ -108,7 +136,13 @@ class TestJacksonWithKotlin {
108136
109137 // ==================
110138
111- private class StateObjectAsNormalClass @JsonCreator constructor(override val name : String , override val age : Int , override val primaryAddress : String , @JsonProperty(" renamed" ) override val wrongName : Boolean , override val createdDt : Date ) : TestFields
139+ private class StateObjectAsNormalClass @JsonCreator constructor(
140+ override val name : String ,
141+ override val age : Int ,
142+ override val primaryAddress : String ,
143+ @JsonProperty(" renamed" ) override val wrongName : Boolean ,
144+ override val createdDt : Date
145+ ) : TestFields
112146
113147 @Test fun testNormalClassWithJsonCreator () {
114148 // normal class
@@ -118,7 +152,11 @@ class TestJacksonWithKotlin {
118152
119153 // ==================
120154
121- private class StateObjectWithPartialFieldsInConstructor (override val name : String , override val age : Int , override val primaryAddress : String ) : TestFields {
155+ private class StateObjectWithPartialFieldsInConstructor (
156+ override val name : String ,
157+ override val age : Int ,
158+ override val primaryAddress : String
159+ ) : TestFields {
122160 @JsonProperty(" renamed" ) override var wrongName: Boolean = false
123161 override var createdDt: Date by Delegates .notNull()
124162 }
@@ -131,13 +169,15 @@ class TestJacksonWithKotlin {
131169
132170 // ==================
133171
134- private class StateObjectAsDataClassConfusingConstructor constructor (@Suppress(" UNUSED_PARAMETER" ) nonField : String? ,
135- override val name : String ,
136- @Suppress(" UNUSED_PARAMETER" ) yearOfBirth : Int ,
137- override val age : Int ,
138- override val primaryAddress : String ,
139- @JsonProperty(" renamed" ) override val wrongName : Boolean ,
140- override val createdDt : Date ) : TestFields
172+ private class StateObjectAsDataClassConfusingConstructor constructor(
173+ @Suppress(" UNUSED_PARAMETER" ) nonField : String? ,
174+ override val name : String ,
175+ @Suppress(" UNUSED_PARAMETER" ) yearOfBirth : Int ,
176+ override val age : Int ,
177+ override val primaryAddress : String ,
178+ @JsonProperty(" renamed" ) override val wrongName : Boolean ,
179+ override val createdDt : Date
180+ ) : TestFields
141181
142182 @Test fun testDataClassWithNonFieldParametersInConstructor () {
143183 // data class with non fields appearing as parameters in constructor, this works but null values or defaults for primitive types are passed to
@@ -162,10 +202,22 @@ class TestJacksonWithKotlin {
162202
163203 // ==================
164204
165- private class StateObjectWithFactory private constructor (override val name : String , override val age : Int , override val primaryAddress : String , override val wrongName : Boolean , override val createdDt : Date ) : TestFields {
205+ private class StateObjectWithFactory private constructor(
206+ override val name : String ,
207+ override val age : Int ,
208+ override val primaryAddress : String ,
209+ override val wrongName : Boolean ,
210+ override val createdDt : Date
211+ ) : TestFields {
166212 var factoryUsed: Boolean = false
167213 companion object {
168- @JvmStatic @JsonCreator fun create (@JsonProperty(" name" ) nameThing : String , @JsonProperty(" age" ) age : Int , @JsonProperty(" primaryAddress" ) primaryAddress : String , @JsonProperty(" renamed" ) wrongName : Boolean , @JsonProperty(" createdDt" ) createdDt : Date ): StateObjectWithFactory {
214+ @JvmStatic @JsonCreator fun create (
215+ @JsonProperty(" name" ) nameThing : String ,
216+ @JsonProperty(" age" ) age : Int ,
217+ @JsonProperty(" primaryAddress" ) primaryAddress : String ,
218+ @JsonProperty(" renamed" ) wrongName : Boolean ,
219+ @JsonProperty(" createdDt" ) createdDt : Date
220+ ): StateObjectWithFactory {
169221 val obj = StateObjectWithFactory (nameThing, age, primaryAddress, wrongName, createdDt)
170222 obj.factoryUsed = true
171223 return obj
@@ -179,9 +231,21 @@ class TestJacksonWithKotlin {
179231 assertThat(stateObj.factoryUsed, equalTo(true ))
180232 }
181233
182- private class StateObjectWithFactoryNoParamAnnotations (val name : String , val age : Int , val primaryAddress : String , val renamed : Boolean , val createdDt : Date ) {
234+ private class StateObjectWithFactoryNoParamAnnotations (
235+ val name : String ,
236+ val age : Int ,
237+ val primaryAddress : String ,
238+ val renamed : Boolean ,
239+ val createdDt : Date
240+ ) {
183241 companion object {
184- @JvmStatic @JsonCreator fun create (name : String , age : Int , primaryAddress : String , renamed : Boolean , createdDt : Date ): StateObjectWithFactoryNoParamAnnotations {
242+ @JvmStatic @JsonCreator fun create (
243+ name : String ,
244+ age : Int ,
245+ primaryAddress : String ,
246+ renamed : Boolean ,
247+ createdDt : Date
248+ ): StateObjectWithFactoryNoParamAnnotations {
185249 return StateObjectWithFactoryNoParamAnnotations (name, age, primaryAddress, renamed, createdDt)
186250 }
187251 }
@@ -197,10 +261,22 @@ class TestJacksonWithKotlin {
197261 }
198262 }
199263
200- private class StateObjectWithFactoryOnNamedCompanion private constructor (override val name : String , override val age : Int , override val primaryAddress : String , override val wrongName : Boolean , override val createdDt : Date ) : TestFields {
264+ private class StateObjectWithFactoryOnNamedCompanion private constructor(
265+ override val name : String ,
266+ override val age : Int ,
267+ override val primaryAddress : String ,
268+ override val wrongName : Boolean ,
269+ override val createdDt : Date
270+ ) : TestFields {
201271 var factoryUsed: Boolean = false
202- companion object Named {
203- @JvmStatic @JsonCreator fun create (@JsonProperty(" name" ) nameThing : String , @JsonProperty(" age" ) age : Int , @JsonProperty(" primaryAddress" ) primaryAddress : String , @JsonProperty(" renamed" ) wrongName : Boolean , @JsonProperty(" createdDt" ) createdDt : Date ): StateObjectWithFactoryOnNamedCompanion {
272+ private companion object Named {
273+ @JvmStatic @JsonCreator fun create (
274+ @JsonProperty(" name" ) nameThing : String ,
275+ @JsonProperty(" age" ) age : Int ,
276+ @JsonProperty(" primaryAddress" ) primaryAddress : String ,
277+ @JsonProperty(" renamed" ) wrongName : Boolean ,
278+ @JsonProperty(" createdDt" ) createdDt : Date
279+ ): StateObjectWithFactoryOnNamedCompanion {
204280 val obj = StateObjectWithFactoryOnNamedCompanion (nameThing, age, primaryAddress, wrongName, createdDt)
205281 obj.factoryUsed = true
206282 return obj
0 commit comments