相关疑难解决方法(0)

找不到Jersey + Json媒体类型应用程序/ json

我正在尝试使用简单的Jersey + JSON示例,但我得到以下错误 message body writer for Java class com.test.jsonexample and MIME media type application/json was not found

我把以下jar文件用于获得适当的结果

asm-3.1.jar
jackson-core-asl-1.9.9.jar
jackson-jaxrs-1.9.9.jar
jackson-mapper-asl-1.9.9.jar
jackson-xc-1.9.9.jar
jersey-client-1.9.jar
jersey-core-1.9.1.jar
jersey-json-1.9.jar
jersey-server-1.9.1.jar
jettison-1.3.2.jar
jsr311-api-1.1.1.jar
Run Code Online (Sandbox Code Playgroud)

为什么我会收到此类错误?错误日志在这里:

SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.test.Jsonexample, and Java type class com.test.Jsonexample, and MIME media type application/json was not found
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at …
Run Code Online (Sandbox Code Playgroud)

java json jax-rs jersey

17
推荐指数
2
解决办法
8万
查看次数

Jersey ClientResponse.getEntity的泛型类型

我使用jeresy ClientRespone.getEntity进行反序列化时遇到问题

我试图遵循一些教程和问题,包括:http : //jersey.576304.n2.nabble.com/How-can-I-parse-a-java-util-List-lt-gt-Is-它支持泽西客户端-tdd2300852.html https://jersey.java.net/nonav/documentation/1.5/json.html http://www.programcreek.com/java-api-examples/的index.php?API = com.sun.jersey.api.client.GenericType

我仍然一遍又一遍地得到同样的例外

我的目标是:而不是:

response.getEntity(String.class); --> {"name":"Ben","type":"The man","id":0}
Run Code Online (Sandbox Code Playgroud)

然后解析它(例如使用Jackson),我想让实体进入我的POJO对象.

到目前为止,这是我的尝试:

服务器端:

@POST
@Path("/account") // route to a specific method.re
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response saveDataIntoHash(Account account) {
    Account createdAccount = new Account(account.getName(), account.getType());
    accountHash.put(createdAccount.getID(), createdAccount);
    return Response.status(201).entity(new AccountResponse(createdAccount.getID())).build();
}
Run Code Online (Sandbox Code Playgroud)

服务器端帐户类:

private String name;
private String type;
private int ID;

private static int classID = 0;

public Account(String name, String type) {
    this.name = name;
    this.type = type;
    this.ID = classID++;
}

public Account() …
Run Code Online (Sandbox Code Playgroud)

java json jax-rs jersey jersey-client

13
推荐指数
1
解决办法
5万
查看次数

使用JSON的Jersey RESTfull服务

我想将JSON-Post中的值解析为Java-Variables.但他们总是空着的!

JSON-帖子:

{"algID":0,"vertices":[1,2,3]}
Run Code Online (Sandbox Code Playgroud)

我尝试将其解析为Java-Variables:

  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Path("getCloseness_vertices")
  public String getCloseness_vertices(
  @FormParam("algID") int algID,
  @FormParam("vertices") IntArray vertices)
Run Code Online (Sandbox Code Playgroud)

如果我这样尝试:

public String getCloseness_vertices(int algID)
Run Code Online (Sandbox Code Playgroud)

Tomcat说:

用于Java类int的消息体读取器,Java类型int和MIME媒体类型application/json; charset =未找到UTF-8.

任何帮助都会很好,我只是不明白.

java parsing json jersey

2
推荐指数
1
解决办法
7634
查看次数

标签 统计

java ×3

jersey ×3

json ×3

jax-rs ×2

jersey-client ×1

parsing ×1