具有自己的列表实现的XStream xml对象

时间:2016-04-21 11:25:49

标签: java xml xstream

我有以下XML:

<Person>
  <siblings>
    <siblings>
      <Sibling>
        <forename>Bob</forename>
        ...
      </Sibling>
    </sibings>
  </siblings>
</Person>

我正在尝试解析Java对象:

public class Person() {
  private Siblings siblings;
}

public class Siblings() {
  private MyList<Sibling> siblings;
}

public class Sibling() {
  private String forename;
}

Siblings类使用java.util.List的实现:

public class MyList<E> extends AbstractList<E> 
    implements List<E>, RandomAccess, Cloneable, java.io.Serializable {
  // code
}

在转换过程中,我收到以下错误:

Exception in thread "main" com.thoughtworks.xstream.converters.ConversionException: Cannot deserialize object with new readObject()/writeObject() methods
---- Debugging information ----
message             : Cannot deserialize object with new     readObject()/writeObject() methods
class               : utils.xtreamtest.MyList
required-type       : utils.xtreamtest.MyList
converter-type      :     com.thoughtworks.xstream.converters.reflection.SerializableConverter
path                : /Person/siblings/siblings
line number         : 3
class[1]            : utils.xtreamtest.Siblings
converter-type[1]   :     com.thoughtworks.xstream.converters.reflection.ReflectionConverter
class[2]            : utils.xtreamtest.Person
version             : 1.4.9
-------------------------------

我猜这是因为xstream不知道MyList类是什么?我是否会使用别名来执行此操作,如果是这样,那么siblings有两个级别。我将无法编辑源代码来添加注释。

0 个答案:

没有答案