[Lift] regression in XML -> JSON conversion in M4

6 views
Skip to first unread message

harryh

unread,
Apr 20, 2010, 1:10:11 PM4/20/10
to Lift
scala> <tips><group type="Foo"></group><group
type="Bar"><tip><text>xxx</text></tip><tip><text>yyy</text></tip></
group></tips>
res0: scala.xml.Elem = <tips><group type="Foo"></group><group
type="Bar"><tip><text>xxx</text></tip><tip><text>yyy</text></tip></
group></tips>

scala> Xml.toJson(res0)
res1: net.liftweb.json.JsonAST.JValue =
JObject(List(JField(tips,JObject(List(JField(group,JArray(List(JObject(List(JField(group,JString()),
JField(type,JString(Foo)))), JObject(List(JField(type,JString(Bar)),
JField(tip,JArray(List(JObject(List(JField(text,JString(xxx)))),
JObject(List(JField(text,JString(yyy)))))))))))))))))

scala> Printer.compact(render(res1))
res2: String = {"tips":{"group":[{"group":"","type":"Foo"},
{"type":"Bar","tip":[{"text":"xxx"},{"text":"yyy"}]}]}}

Note the extra group String in res2.

-harryh


--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Joni Freeman

unread,
Apr 20, 2010, 1:45:28 PM4/20/10
to Lift
Hi,

I have fix in my local branch now. I'll put it to reviewboard soon
(the fix will be in M5 then). Meanwhile, you can work around the bug
by fixing the JSON by post processing it:

Xml.toJson(res0).remove {
case JField("group", JString("")) => true
case _ => false
}

Cheers Joni

harryh

unread,
Apr 20, 2010, 4:36:32 PM4/20/10
to Lift
Will your fix also handle this break (related, but not identical):

scala> <tips><group type="Nearby"/></tips>
res0: scala.xml.Elem = <tips><group type="Nearby"></group></tips>

scala> Printer.compact(render(Xml.toJson(res0)))
res1: String = {"tips":{"group":"","type":"Nearby"}}

Joni Freeman

unread,
Apr 21, 2010, 1:19:22 AM4/21/10
to Lift
Yes, it fixes that too.

Cheers Joni
Reply all
Reply to author
Forward
0 new messages