Search code examples
javaserializationrestletxstream

Remove '@class' in XStream for Java primitive types


I have this field in a POJO that is serialized into JSON:

@XStreamAlias("tags")
List<String> tags;

My problem is that the output looks like this:

"tags": [
      {
        "@class": "linked-list",
        "string": [
          "test",
          "test2"
        ]
      }
    ],

In what way that the output would look like this:

"tags": [
          "test",
          "test2"
        ],

Just like this.


Solution

  • The solution is to add @XStreamImplicit annotation:

    @XStreamImplicit(itemFieldName="tags")
    List<String> tags;