Jersey:找不到媒体类型= application/json的MessageBodyWriter,类型= class org.codehaus.jackson.node.ObjectNode?

 另一种Xing福_290 发布于 2023-01-15 16:33

Jersey 2.8 Client用来将数据发布到RESTful端点.代码看起来像

    final Client client = ClientBuilder.newClient();
    final WebTarget target = client.target(url).path("inventorySummary");
    final Invocation.Builder builder = target.request().header("Content-Type", MediaType.APPLICATION_JSON);

    final ObjectNode payload = getObjectMapper().createObjectNode();
    payload.put("startDate", DateTime.now().toString());
    payload.put("endDate", DateTime.now().plusDays(30).toString());
    payload.put("networkId", 0);

    final Response response = builder.accept(MediaType.APPLICATION_JSON).post(Entity.entity(payload, MediaType.APPLICATION_JSON));
    assertStatus(Response.Status.OK.getStatusCode(), response);
    final JsonNode jsonReply = parseResponse(response);

getObjectMapper()看起来像

public ObjectMapper getObjectMapper() {
        return new ObjectMapper()
                .configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false /* force ISO8601 */)
                .configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true)
                .configure(DeserializationConfig.Feature.READ_ENUMS_USING_TO_STRING, true)
                .setSerializationInclusion(JsonSerialize.Inclusion.ALWAYS);
    }

当我尝试运行测试时,我看到错误为

MessageBodyWriter not found for media type=application/json, type=class org.codehaus.jackson.node.ObjectNode, genericType=class org.codehaus.jackson.node.ObjectNode

我在这里错过了什么?

谢谢

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有