Jersey - MessageBodyWriter not found application/xml ArrayList (with jersey-jaxb in war)

本秂侑毒 提交于 2020-01-15 10:56:07

问题


I have a Jersey controller that is returning a List<MyPojo> (it is actually returning an ArrayList. My pom includes jersey-server and so I am automatically getting jersey-media-jaxb and I have verified that my war does contain that dependency.

The endpoint is marked with:

@Produces(value={MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})

When I hit it with no accept specified (or with application/json) I get back JSON with no issues. But when I specify 'accept=application/xml` I get:

MessageBodyWriter not found for media type=application/xml, type=class java.util.ArrayList, genericType=java.util.List<MyPoJo>

Not sure if it matters, but I am using Spring boot but I am not using the jersey starter due to version issues.

Update

As a note: this worked using Spring MVC and the default output was XML.

I can't copy/paste the method but here is outline Method:

@Get
@Path("/since")
@Produces(value={MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<MyMetadata> since(){
   return callService(paramaters);
}

// The below pre-existed me
public class MyMetadata{
    private String id;

    @JsonSerialize(using=DateTimeSerializer.class)
    @JsonDeserialize(using=MyDateTimeDeserializer.class)
    private DateTime startTime;

     private List<String> ids;

     private List<OtherPojo> uuids;

     private SecurityPojo security;

     private Set<MyTuples> ads;
}

来源:https://stackoverflow.com/questions/41616012/jersey-messagebodywriter-not-found-application-xml-arraylist-with-jersey-jaxb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!