On Wed, Sep 5, 2018 at 1:18 AM <[email protected]> wrote:
>
> I need to serialize/deserialze some xml data like this:
>
> <MyObject>
> <MyPropA>1</MyPropA>
> <MyPropA>2</MyPropA>
> ...
> <MyPropB>a</MyPropB>
> <MyPropB>b</MyPropB>
> <MyPropB>c</MyPropB>
> ...
> <MyPropA>3</MyPropA>
> <MyPropA>4</MyPropA>
> <MyPropA>5</MyPropA>
> ...
> </MyObject>
>
>
> Where MyPropB has to have at least 1 element! So even for deserialization
> it's clear where all the MyPropA items belong to.
>
>
> This simple approach does (of course) not work:
>
> class MyObject {
>
> @JsonProperty(value = "MyPropA")
> private List<String> myPropA1;
> @JsonProperty(value = "MyPropB")
> private List<String> myPropB;
> @JsonProperty(value = "MyPropA")
> private List<String> myPropA2;
>
> }
>
>
> because of the duplicate property name MyPropA.
>
> Any idea how to define/annotate classes to achieve this goal?
There is no declarative method (that is, only using annotations), but
you should be able to define class to use setter:
public void setMyPropA(List<String> values {
// keep track of what has been populated, assign appropriately
}
and it will actually get called multiple times, once per sequence of
contiguous values.
But you will need to track state yourself, possibly by initializing
fields appropriately or
adding a separate state-tracking field (initialized in constructor).
I hope this helps,
-+ Tatu +-
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.