File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
main/scala/net/liftmodules/jsonextractorng Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -90,8 +90,8 @@ object Extraction {
9090 val customDeserializer = formats.customDeserializer(formats)
9191
9292 root match {
93- case obj @ JObject (_) if formats.customSerializers.nonEmpty &&
94- customDeserializer.isDefinedAt(ctor.typeInfo, obj) =>
93+ case obj if formats.customSerializers.nonEmpty &&
94+ customDeserializer.isDefinedAt(ctor.typeInfo, obj) =>
9595 customDeserializer(ctor.typeInfo, obj)
9696
9797 case obj @ JObject (fields) =>
Original file line number Diff line number Diff line change @@ -121,6 +121,27 @@ class ExtractionNgSpec extends FlatSpec with Matchers {
121121
122122 output should equal(Baconizer2 [String ](" Testy McTestface" , 3.14 ))
123123 }
124+
125+ it should " properly handle a custom deserializer for a non JObject" in {
126+ val customDeserializer = new Serializer [Baconizer ] {
127+ val clazz = classOf [Baconizer ]
128+ override def serialize (implicit formats : Formats ) = ???
129+
130+ override def deserialize (implicit formats : Formats ) = {
131+ case (TypeInfo (`clazz`, None ), json) =>
132+ json match {
133+ case JString (s) => Baconizer (" Testy McTestface" , 3.14 )
134+ case x => throw new RuntimeException (" Can't convert " + x + " to SomethingWithACustom" )
135+ }
136+ }
137+ }
138+
139+ implicit val formats = DefaultFormats + customDeserializer
140+ val input : JString = JString (" Testy McTestface" )
141+ val output = input.extractNg[Baconizer ]
142+
143+ output should equal(Baconizer (" Testy McTestface" , 3.14 ))
144+ }
124145}
125146
126147case class SimpleCaseClass (name : String , age : Int )
You can’t perform that action at this time.
0 commit comments