Depending on the structure of the XML, attributes and child elements
are being lost. This can be seen in example 4, where the attribute
expiry_date and the child element status have been dropped.

It would also appear when XML is being converted to JSON attributes
are being flattened to elements. I'm not sure if this is expected or
not, this can be seen in examples  1,2 & 3. The child
element status with attribute count is converted to two attributes
status with a value of null and count with the correct value.

To test I added the following before the closing brace of
XmlExamplesTest.scala in lift-json.

Is this a bug or my error ?

Cheers
Jono

P.S I've noticed this could be related to the thread "Possible lift-
json bug in Xml.toJson"
http://groups.google.com/group/liftweb/browse_thread/thread/47c581d63ddc04c5/86a11ffcf3040aaa?lnk=gst&q=Json+#86a11ffcf3040aaa

/*==== Test  ====*/

  import scala.xml.Node

 def xml2Json(xml:Node):String = {
    val json = toJson(xml)
    compact(render(json))
  }

  "XML to JSON Example with multiple attributes, multiple nested
elements " in  {  xml2Json(xml1) mustEqual expected1 }
  "XML to JSON Example with multiple attributes, multiple nested
elements "  in  {  xml2Json(xml2) mustEqual expected2 }
  "XML to JSON Example with one attribute,  multiple nested elements
" in  {  xml2Json(xml3) mustEqual expected3 }
  "XML to JSON Example with one attribute, one nested element " in
{  xml2Json(xml4) mustEqual expected4 }

val xml1         = <message expiry_date="20091126" text="text"
word="ant" self="me"><stats count="0"></stats><messages href="https://
domain.com/message/ant"></messages></message>
val expected1 = """{"message":{"expiry_date":
20091126,"text":"text","word":"ant","self":"me","stats":{"count":
0},"messages":{"href":"https://domain.com/message/ant"}}}""";
val actual1     = """{"message":
{"expiry_date":"20091126","word":"ant","text":"text","self":"me","stats":null,"count":"0","messages":null,"href":"https://
domain.com/message/ant"}}"""

val xml2         = <message expiry_date="20091126" text="text"
word="ant" self="me"><stats count="0"></stats><messages href="https://
domain.com/message/ant"></messages></message>
val expected2 = """{"message":{"expiry_date":
20091126,"text":"text","word":"ant","self":"me","stats":{"count":
0},"messages":{"href":"https://domain.com/message/ant"}}}""";
val actual2      = """{"message":
{"expiry_date":"20091126","word":"ant","text":"text","self":"me","stats":null,"count":"0","messages":null,"href":"https://
domain.com/message/ant"}}"""

val xml3          = <message expiry_date="20091126"><stats count="0"></
stats><messages href="https://domain.com/message/ant";></messages></
message>
val expected3  = """{"message":{"expiry_date":20091126,"stats":
{"count":0},"messages":{"href":"https://domain.com/message/ant"}}}""";
val actual3      = """{"message":
{"expiry_date":"20091126","stats":null,"count":"0","messages":null,"href":"https://
domain.com/message/ant"}}"""

val xml4          = <message expiry_date="20091126"><stats count="0"></
stats></message>
val expected4  = """{"message":{"expiry_date":20091126,"stats":
{"count":0}}}"""
val actual4      = """{"message":""}"""

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

Reply via email to