Is there a simple way for marshalling and unmarshalling String[] or List in RESTEasy?
My code sample :
@GET
@Path("/getSomething")
@Produces(MediaType.APPLICATION_JSON)
public List<String> getSomeData() {
return Arrays.asList("a","b","c","d");
}
Above gives me an Exception :
Could not find MessageBodyWriter for response object
of type: java.util.Arrays$ArrayList of media type: application/json
You might need to wrap it like this:
public List<JaxbString> getList(){
List<JaxbString> ret= new ArrayList<JaxbString>();
List<String> list = Array.asList("a","b","c");
for(String s:list){
ret.add(new JaxbString(s));
}
return ret;
}
@XmlRootElement
public class JaxbString {
private String value;
public JaxbString(){}
public JaxbString(String v){
this.setValue(v);
}
public void setValue(String value) {
this.value = value;
}
@XmlElement
public String getValue() {
return value;
}
}
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