2016-06-02 3 views
0

Resteasy를 사용하고 있으며 내 리소스에서 문자열 목록 만 반환하려고합니다. JSON과 작동하지만 XML의 경우 Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/xml이라는 오류가 있습니다.No MessageBodyWriter for application/xml

어떻게해야합니까? 웹에서 옵션을 시도했지만 아무것도 작동하지 않았습니다. pom.xml 파일에서

@GET 
@Path("") 
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) 
@Wrapped(element = "resources") 
public Response getResources() { 

    List<String> resources = ts.getAllResources(); 
    //GenericEntity<List<String>> entity = new GenericEntity<List<String>>(resources) {}; 

    return Response.ok().entity(new GenericEntity<List<String>>(resources) {}).build(); 
    //return Response.ok(resources).build(); 
    //return resources; 
} 

추출

<dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxrs</artifactId> 
     <version>${jboss.resteasy.version}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-servlet-initializer</artifactId> 
     <version>${jboss.resteasy.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxb-provider</artifactId> 
     <version>${jboss.resteasy.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-atom-provider</artifactId> 
     <version>${jboss.resteasy.version}</version> 
    </dependency> 

UPDATE : 나는대로 제이보스 (10)

WFLYSRV0059: Class Path entry jaxb-api.jar in /D:/Dev/Servers/wildfly-10.0.0.Final/standalone/deployments/service.war/WEB-INF/lib/jaxb-core-2.2.7.jar does not point to a valid jar for a Class-Path reference. 
+0

클래스에'@ XmlRootElement' 주석을 달고 있습니까? – taoxiaopang

+0

어떤 등급입니까? 웹 서비스를 구현하는 사람? – jlanza

답변

0

에 배포 할 때 나는 또한 다음과 같은 오류가있는 것으로 나타났습니다 직접 작동시키지 못했습니다. 목록을 캡슐화하는 클래스를 만드는 방법을 만들었습니다 :

@XmlRootElement(name = "resources") 
public static class ResourcesListSerializerHelper { 
    @XmlElement(name = "resource") 
    @JsonProperty(value = "resources") 
    public List<String> resources = new ArrayList<String>(); 

    public ResourcesListSerializerHelper() { 
    } 

    public ResourcesListSerializerHelper(List<String> list) { 
     resources.addAll(list); 
    } 
} 

@GET 
@Path("") 
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) 
public Response getResources() { 
    List<String> resources = ts.getAllResources(); 
    return Response.ok().entity(new ResourcesListSerializerHelper(resources)).build(); 
} 
관련 문제