【问题标题】:RestEasy - Unable to find MessageBodyReader ... application/xml?RestEasy - 无法找到 MessageBodyReader ... application/xml?
【发布时间】:2016-02-17 11:23:00
【问题描述】:

我从 2 天开始尝试查找有关此问题的信息,但仍然不明白。我让我的 Maven 项目在 Wildfly 上运行。

休息代码:

@Override
    @GET
    @Path("{id}")
//  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
    public Customer getOverId(@PathParam("id") String id) {
        logger.info("put in " + this.getClass().getName() + " over id " + id);
//      if (id != null) {
//          Customer object = service.loadOneCustomer(new Integer(id));
//          logger.info("found in " + this.getClass().getName());
//          return Response.ok(object).build();
//      }
        Customer customer = service.loadOneCustomer(new Integer(id));
//      logger.info("nix found");
        if(customer == null) {
            throw new NotFoundException("No customer found with the matching ID: " + id);
        }
        logger.info("Customer found: " + customer.getCustomerNumber());
//      return Response.status(Status.BAD_REQUEST).build();
        return customer;
    }

客户端实现:

public Response readCustomer(String id){
        log.info("Starting: Rest get a Customer with ID: " + id);
        log.info(this.URL);
        this.customerWebTarget = this.client.target(this.URL).path(id);
        Response response = this.customerWebTarget.request().buildGet().invoke();

//      TODO Customer cast application_xml auf Customer? Customer customer = response.readEntity(Customer.class);
        Customer customer = response.readEntity(Customer.class);

        log.info("Ending: Rest invoque a Customer with ID:" + customer.getCustomerNumber());
//      System.out.println("Ending: Rest get a Customer with ID: " + response.readEntity(String.class));

        return response;
    }

J 单元测试:

@Test
    public void testGetCustomerById() throws Exception {

        Response response = this.customerRestClient.readCustomer("112");
        System.out.println("--->" + response.getStatus());
        Assert.assertTrue(response.getStatus() == 200);
    }

一切正常,直到我尝试从我得到的 XML 中获取 Java 对象(客户 customer = response.readEntity(Customer.class);)

我错过了什么吗?我的意思是,我读取了 xml-File 并查看其中的所有数据...为什么我不能将其转换为 Java-Object?

我总是得到这个错误:

Javax.ws.rs.ProcessingException: Unable to find a MEssageBody of content-type-application/xml and type class de.....model.Customer

【问题讨论】:

  • 发布代码时,请删除所有仅说明您的尝试和错误但无助于解释问题的陈述和cmet。

标签: wildfly resteasy java-ee-7


【解决方案1】:

请您发布客户类。是否正确注释? 还要重新添加@Produces。

【讨论】:

  • 这可能是一条评论,但没有答案。
  • @hwellmann,没有足够的声誉来评论这个问题:) & 所以作为答案发布。
【解决方案2】:

没有看到Customer 类,很难判断,但很可能缺少部分或全部 JAXB 注释。特别是,您需要一个 @XmlRootElement 注释。

【讨论】:

    猜你喜欢
    • 2013-05-03
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 2014-03-27
    相关资源
    最近更新 更多