简体   繁体   English

简单的 XML 框架和 Android - 奇怪的 class 属性

[英]Simple XML Framework and Android - strange class attribute

I am trying to use the Simple XML library with Android and getting some errors with it ( http://pastebin.com/7Nrk1esD ), where the main error is this:我正在尝试将 Simple XML 库与 Android 一起使用,但出现了一些错误 ( http://pastebin.com/7Nrk1esD ),其中主要错误是:

"org.eclipse.persistence.indirection.IndirectList in loader dalvik.system.PathClassLoader..."

The Model which has to be deserialized is also used by a rest-server to produce the necessary XML, there are also some JPA-annotations like the following:必须反序列化的 Model 也被 rest-server 用来生成必要的 XML,还有一些 JPA 注释,如下所示:

@OneToMany
@ElementList(required = false)
private List<Substance> substances = new ArrayList<>();

this line produces the following xml output:该行产生以下 xml output:

<substances class="org.eclipse.persistence.indirection.IndirectList">
...
</substances>

Here I see now where the error is coming from - Android is not aware of org.eclipse.persistence: But my question is now: Why is the line class="...IndirectList" produced and how can I change that to avoid the errors in the Android application?在这里,我现在看到错误的来源 - Android 不知道 org.eclipse.persistence:但我现在的问题是:为什么会生成行class="...IndirectList"以及如何更改它以避免Android 应用程序中的错误?

PS: I am using simple 2.6.2 PS:我用的是simple 2.6.2

thanks in advance!提前致谢!

Found the Answer here :这里找到答案:

Strategy strategy = new TreeStrategy("clazz", "len");
Serializer serializer = new Persister(strategy);

But I use this snippet only in the Android-client to deserialize and NOT to serialize the model in the server.但是我只在 Android 客户端中使用这个片段来反序列化而不是在服务器中序列化 model。

Try this试试这个

@OneToMany
@Path("substances")
@ElementList(required = false, inline=false)
private List<Substance> substances = new ArrayList<>();

This should work.这应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM