Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json JAX-RS客户端在POJO对象中发送/接收消息_Json_Jersey_Jax Rs_Jersey 2.0 - Fatal编程技术网

Json JAX-RS客户端在POJO对象中发送/接收消息

Json JAX-RS客户端在POJO对象中发送/接收消息,json,jersey,jax-rs,jersey-2.0,Json,Jersey,Jax Rs,Jersey 2.0,我有以下代码可以工作。它使用POST方法向JAX-RSWeb服务发送JSON请求,并接收回JSON响应。JSON请求和响应都是字符串对象。但是,我希望它们被封装在POJO对象中,这样我发送一个POJO对象,响应将在POJO对象中。我该怎么做 ClientConfig config = new ClientConfig(); Client client = ClientBuilder.newClient(config); WebTarget target = client.target(UriBu

我有以下代码可以工作。它使用POST方法向JAX-RSWeb服务发送JSON请求,并接收回JSON响应。JSON请求和响应都是字符串对象。但是,我希望它们被封装在POJO对象中,这样我发送一个POJO对象,响应将在POJO对象中。我该怎么做

ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target(UriBuilder.fromUri("http://.....").build());
Invocation.Builder builder = target.path("Test").request();
builder = builder.accept(MediaType.WILDCARD);
String jsonRequest = "{ "staffID":"123456", "token":"010101" }";
Response response = builder.post(Entity.json(jsonRequest));
String jsonResponse = response.readEntity(String.class);
System.out.println(jsonResponse);

我下载了所有的Jackson JAR文件。然后,我将代码更改为以下代码,它可以工作:POJO POJO=new POJO();pojo.setStaffID(“A111111”)。。。response=builder.post(Entity.Entity(pojo,MediaType.APPLICATION_JSON));POJO responsePOJO=response.readEntity(POJO.class);在运行于Weblogic 12.2.1上的JAX-RS web服务中,我不需要Jackson。但它能够将POJO转换为JSON,也可以从JSON转换为POJO。这是签名:公共响应getNotifications(@Context-HttpServletRequest-request,POJO-requestBody);为什么web服务没有在war文件中捆绑Jackson就可以工作?是的,peeskillet。客户端代码现在可以工作了。只要包含jacksonjar文件并将代码更改为上面的代码,就可以工作。现在我很想知道为什么我的web服务不需要Jackson,但仍然可以将POJO转换为JSON或从JSON转换为JSON。Weblogic已经有了一个JSON提供程序,但是1)这是用于服务器的2)如果您在服务器上使用客户机,这是因为Weblogic默认使用Jersey 1.x。它不会识别JAX-RS2.x客户机,也不会向客户机注册提供程序。如果您使用Jersey 1.x客户机,我可以想象您不需要注册任何提供程序,它只需要使用服务器提供的一个提供程序。jarsI可能是错误的,我不使用WebLogic,但从其他文章中我记得的情况来看,Jersey 1.x是JAX-RS 1.1。WebLogic中的实现。它不使用JAX-RS2.0