I see two problems here:
<rs><r>...</r></rs>
are nested tags of the root element (not sure if@Path
can handle this ...)- the two tags of each entry (
<c><v>...</v></c>
) are not possible through@ElementList
annotations (and@Path
can't be set for each entry)
As a solution you can write two wrapper classes:
- One, that wraps the root-node
- Another one, that's put in the list, wrapping each a entry
And here comes the implementation:
Class FooWrapper
This class wraps a Foo
class; you get rs-tag through the wrapper and the r-tag with the actual object.
@Root(name = "rs")
public class FooWrapper
{
@Element(name = "r", required = true)
private Foo f;
public FooWrapper(Foo f) // Required just in case you want to serialize this object
{
this.f = f;
}
FooWrapper() { } // At least a default ctor is required for deserialization
}
Class Foo
Nothing special here. Only the type of the list entries is changed to the EntryWrapper
.
@Root(strict = false)
public class Foo /* A */
{
@Element(name = "id")
public int id; /* B */
@Element(name="bar")
public String info;
@ElementList(entry="c", inline=true, required=false, empty = false)
public List<EntryWrapper> values; // Replacing the String with the EntryWrapper
// ...
}
/* A */
: In your code, this wasstatic
too, i've just removed it since i put it into a own class file./* B */
: Better: encapsulate the fields, make themprivate
and write getter / setter.
Class EntryWrapper
Each entry in the list is wrapped into such a wrapper object. Btw. no need to expose this class public
.
public class EntryWrapper
{
@Element(name = "v")
private String value;
public EntryWrapper(String value)
{
this.value = value;
}
EntryWrapper() { } // Once again, at least one default ctor is required for deserialization
// ...
}