@@ -54,6 +54,13 @@ object CreatorTest
5454 }
5555 }
5656
57+ case class CaseClassAlternativeConstructor (script : String , dummy : Int ) {
58+ @ JsonCreator
59+ def this (script : String ) = {
60+ this (script, 0 )
61+ }
62+ }
63+
5764 case class MultipleConstructors (script : String , dummy : Int ) {
5865 def this (script : String ) = {
5966 this (script, 0 )
@@ -123,6 +130,19 @@ class CreatorTest extends DeserializationFixture {
123130 roundTrip shouldEqual orig
124131 }
125132
133+ it should " use secondary constructor annotated with JsonCreator (Case Class)" in { f =>
134+ val orig = CaseClassAlternativeConstructor (" abc" , 42 )
135+ val bean = f.writeValueAsString(orig)
136+ bean shouldBe """ {"script":"abc","dummy":42}"""
137+ val roundTrip = f.readValue(bean, classOf [CaseClassAlternativeConstructor ])
138+ roundTrip shouldEqual orig
139+
140+ // this part of test relies on the 2nd constructor being used (with the JsonCreator annotation)
141+ val bean2 = """ {"script":"abc"}"""
142+ val cc2 = f.readValue(bean2, classOf [CaseClassAlternativeConstructor ])
143+ cc2 shouldEqual CaseClassAlternativeConstructor (" abc" , 0 )
144+ }
145+
126146 it should " use primary constructor if no JsonCreator annotation" in { f =>
127147 val orig = MultipleConstructors (" abc" , 42 )
128148 val bean = f.writeValueAsString(orig)
0 commit comments