Search code examples
javaserializationjacksonxstreamswagger

Jackson equivalent to XStreamImplicit


I am having an issue with Jackson and I need to find a way to get the following object to serialize correctly to support swagger docs.

public Class Foo{
  @XStreamImplicit
  List<Bar> bars;
}

When serialized with XStream this would look something like:

<Foo>
  <Bar>b1</Bar>
  <Bar>b2</Bar>
</Foo>

What we would like is to have a similar display in JSON but I don't know if this is possible as JSON I believe is essentially a K,V map.

{
"bar":"b1",
"bar":"b2"
}

Clarification on any of these points would be very helpful!

EDIT:

Looks like the issue lies in swagger, adding the array notation still does not allow the Response Model to be populated for the different response codes. We believe there is an issue with the annotation not handling collections.


Solution

  • That's not a map but rather an array. In JSON, you can't have multiple keys with the same name. The JSON equivalent will look like this:

    {
      "bar": [ "b1", "b2" ]
    }