Is XStream serialization enough with Scala?

I am trying to use XStream to quickly serialize objects in Xml or JSON for wire and deserialization. I want the XML / JSON to be simple / clean.

Everything seems to be fine, I added a few aliases, but now I got into the problem, this code:

println(new XStream.toXML(List(1,2,3)))

creates this XML:

<scala.coloncolon serialization="custom">
  <unserializable-parents/>
  <scala.coloncolon>
    <int>1</int>
    <int>2</int>
    <int>3</int>
    <scala.ListSerializeEnd/>
  </scala.coloncolon>
</scala.coloncolon>

I think it happens that the Scala List class has its own serialization ... I wonder if there is a way to override this? I would prefer:

<list>
  <int>1</int>
  <int>2</int>
  <int>3</int>
</list>
+3
source share
2 answers

I figured out how to write a converter for Scala List to get xml, as shown above, see

XStream Scala? ?

+1

"coloncolon" ::, cons, Scala List. List. List Nil, .

, - , , .

, Nil.

+1

Source: https://habr.com/ru/post/1723160/


All Articles