How can I get XStream to output Scala lists nicely? Can I write a custom converter?

时光怂恿深爱的人放手 提交于 2019-11-30 20:51:26

Not seconds after posting the question, the answer came to me, here is a working implementation of unmarshal:

  def unmarshal( reader: HierarchicalStreamReader, context: UnmarshallingContext ) = {
    var list : List[_] = Nil 
    while (reader.hasMoreChildren()) {
      reader.moveDown();
      val item = readItem(reader, context, list);
      list = list ::: List(item) // be sure to build the list in the same order
      reader.moveUp();
    }
    list
  }

There is only one instance of an empty list, which is the object Nil.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!