I'm using JAXB/Jersey (1.3) to convert java to json in a REST API. The java class I'm returning is like:
public class MyClass {
List<String> myTags;
public List<String> getMyTags() {
return myTags;
}
}
My problem is that if there is only a single element in the list myTags, then the data is converted to json as a string object, not an array of strings. That is, I get:
{
"myTags": "myString"
}
What I want is:
{
"myTags": ["myString"]
}
Anyone know whats up ?
As per Luciano's comments, the problem lies in the fact that Jersey wasn't using Jackson as the default JSON converter. I tried excluding Jettison from the pom dependency, but it still didn't resolve the issue. I found an answer to explicitly tell Jersey to use Jackson here:
How can I customize serialization of a list of JAXB objects to JSON?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With