简体   繁体   English

找不到Java类型类java.util.ArrayList和MIME媒体类型application / xml的消息正文编写器

[英]A message body writer for Java type, class java.util.ArrayList, and MIME media type, application/xml, was not found

This is the code I am calling from Android 这是我从Android调用的代码

    RESTClient rs = new RESTClient(WebServicePatterns.SERVICES_URL);
    rs.addParam("role_id", "6");
    try
    {
    rs.sendParams_receiveText();// Call WebService
    }

    rs.getResponse()

Here is my RESTClient's method. 这是我的RESTClient的方法。

public void sendParams_receiveText() throws Exception 
{
    http_client = new DefaultHttpClient();
    http_post = new HttpPost(uri);
    http_post.setEntity(new UrlEncodedFormEntity(params));
    http_response = http_client.execute(http_post);
    http_entity = http_response.getEntity();

    response =  EntityUtils.toString(http_entity);
}

Here is my Server side Web Service Code 这是我的服务器端Web服务代码

@Produces("application/xml")
@Path("Services")
@Singleton
public class Services_Service
{
    public Services_Service()
    {

    }

@POST
@Path("getServices")
public List<ServicesBean> getServices(@FormParam("role_id") String role_id) 
{

    Services_DB db = new Services_DB();
    List<ServicesBean> services_data = db.myServices(role_id); 
    return services_data;
}

}

here is myServices code 这是myServices代码

.........
private TreeMap<Integer, ServicesBean>  servicesData    = new TreeMap<Integer, ServicesBean>();
.........

public List<ServicesBean> myServices(String role_id)
{

    List<ServicesBean> entireList = new ArrayList<ServicesBean>();
    ServicesBean bean = new ServicesBean();

    try
    {

        sql = "SELECT A,B,C from TESTTable where .......";

        rs = stmt.executeQuery(sql);

        if (rs != null && rs.next())
        {
            do
            {
                bean = new ServicesBean();

                bean.setService_id(rs.getString("A"));
                bean.setService_name(rs.getString("B"));
                bean.setService_short_name(rs.getString("C"));

                int id = servicesData.size();
                servicesData.put(id, bean);

            } while (rs.next());
        }

        entireList.addAll(servicesData.values());
    } 


    return entireList;

The problem is I am getting Errors like this. 问题是我收到这样的错误。

7 Oct, 2013 5:08:05 PM com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java type, class java.util.ArrayList, and MIME media type, application/xml, was not found
7 Oct, 2013 5:08:05 PM com.sun.jersey.server.impl.application.WebApplicationImpl onException
SEVERE: Internal server error
javax.ws.rs.WebApplicationException
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:241)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:724)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:647)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:638)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:309)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:590)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

Could Someone please help me out. 有人可以帮我吗。

A message body writer for Java class java.util.ArrayList, and Java type java.util.ArrayList, and MIME media type application/xml was not found 找不到Java类java.util.ArrayList,Java类型java.util.ArrayList和MIME媒体类型application / xml的消息正文编写器
Problem was solved by adding XmlRootElement at the begining of the class (See jaxb documentation) (Need jaxb-impl.jar and jaxb-api.jar in server classpath) 通过在类的开头添加XmlRootElement来解决问题(请参阅jaxb文档)(服务器类路径中需要jaxb-impl.jar和jaxb-api.jar)

import javax.xml.bind.annotation.XmlRootElement; 导入javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement @XmlRootElement

The error message is telling you, that Jersey does not know how to transform your List of ServiceBean objects into valid xml. 错误消息告诉您,Jersey不知道如何将ServiceBean对象List转换为有效xml。

What you are missing is an object marshaller like JAXB which does this job for you. 您所缺少的是像JAXB这样的对象编组器,它可以为您完成这项工作。

Take a look at chapter 6 of this tutorial . 看一下本教程的第6章。 It is well explained. 这是很好的解释。

Well a sort and simple answer is. 一个简单而简单的答案是。 You can not transform directly list to the xml. 您不能直接将列表转换为xml。 You need to put list into the class means make your user defined data type and put list into it. 您需要将列表放入类中,这意味着使用户定义数据类型并将列表放入其中。

you can mark class as @XmlRootElement 您可以将类标记为@XmlRootElement

then it will be convert to the XML. 然后将其转换为XML。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未找到Java类java.util.ArrayList ...和MIME媒体类型text / xml的消息正文编写器 - A message body writer for Java class java.util.ArrayList…and MIME media type text/xml was not found 严重:未找到 Java 类 java.util.ArrayList 和 MIME 媒体类型 application/json 的消息正文编写器 - SEVERE: A message body writer for Java class java.util.ArrayList and MIME media type application/json was not found 找不到Java类java.util.ArrayList和MIME媒体类型application / json的消息正文编写器 - A message body writer for Java class java.util.ArrayList and MIME media type application/json was not found 找不到Java类java.util.ArrayList和Java类型类java.util.ArrayList和MIME媒体类型application / json的消息正文编写器 - A message body writer for Java class java.util.ArrayList, and Java type class java.util.ArrayList, and MIME media type application/json was not found 找不到用于Java类型,类bookInfoListType和MIME媒体类型application / xml的消息正文编写器 - A message body writer for Java type, class bookInfoListType, and MIME media type application/xml was not found 找不到用于Java类型myPackage.Sample和MIME媒体类型application / xml的消息正文编写器 - A message body writer for Java type, class myPackage.Sample, and MIME media type, application/xml, was not found 找不到用于Java类型org.json.JSONObject和MIME媒体类型application / json的消息正文编写器 - A message body writer for Java type, class org.json.JSONObject, and MIME media type, application/json, was not found Java类java.util.ArrayList的消息体编写器 - A message body writer for Java class java.util.ArrayList 找不到媒体类型=应用程序/json,类型=类 java.util.ArrayList 的 MessageBodyWriter - MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList Weblogic配置错误-找不到Java类和Java类型类以及MIME媒体类型application / json的消息正文编写器 - Weblogic config error - Message body writer for Java class, and Java type class, and MIME media type application/json was not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM