如何使用JSON作为REST Web服务的PUT和POST方法中的输入来使用Java [英] How to Consume JSON as input in PUT and POST method of REST webservice in java

查看:152
本文介绍了如何使用JSON作为REST Web服务的PUT和POST方法中的输入来使用Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JAX-RS创建REST Web服务.在这种情况下,我有PUT方法或POST方法,它们将json作为REST Web服务中的媒体类型使用.我可以知道如何从客户端调用这些方法.我们如何将json作为来自客户端的输入传递给那些PUT和POST方法,以及如何从服务器端使用PUT或POST方法使用json格式.如果要使用xml,那么我们正在使用JAXBElement.对于使用json,该怎么做?

I am trying to create a REST web service using JAX-RS. In that, I have PUT method or POST method which consumes the json as mediatype in the REST web service. Can I know how to call these methods from the client side. How do we pass that json as input from client side to those PUT and POST method and how would we consume the json format in the PUT or POST method from server side. If we want to consume xml, then we are using JAXBElement. For consuming json, how to do that ?

推荐答案

这可能有助于您前进: http://blog.sertik.net/labels/jersey.html

This may help get you going: http://blog.sertik.net/labels/jersey.html

从我(极其生锈)的回忆中,您可以像对待@POST方法一样对待@PUT方法.因此,如该博客条目中所示,请尝试使用@FormParam批注.另外,请仔细阅读Jersey API,以查看是否有任何有用的东西.

From my (extremely rusty) recollection, you sort of treat the @PUT methods the same way you treat @POST methods. So as shown in that blog entry, try using the @FormParam annotations. Also, read over the Jersey API to see if anything looks useful.

它们之间的主要区别(PUT/POST)在含义上; PUT通常会在uri处创建一个新资源,而POST可以附加"到该资源(POST的功能还有其他一些含义).

The main difference between them (PUT/POST) is in the meaning; PUT typically creates a new resource at the uri, whereas POST can 'append to' it (there are also a few other meanings to what exactly POST does).

PS几乎忘了提及,cURL是如此....不错.

PS almost forgot to mention, cURL is so.... nice.

这篇关于如何使用JSON作为REST Web服务的PUT和POST方法中的输入来使用Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆