在Jersey Rest Service中将Json请求作为Json对象使用的方式 [英] Way to Consume Json request as Json object in Jersey Rest Service

查看:130
本文介绍了在Jersey Rest Service中将Json请求作为Json对象使用的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Google搜索,但是找不到我想要实现的解决方案.

Hi I tried googling around but cannot find solution that I want to achieve.

将json映射到我们做的java对象的示例

Example to map json to java object we do

 @POST
 @Consumes(application/json)
 @Produces(application/json)
 public Response createUpdateDeleteManualClinicalData(MyJavaPojo definedPojo) {
   // this maps any json to a java object, but in my case I am dealing with generic json structure
}

我要实现的是将其保留为json对象本身

What I want to achieve is Keep it as json object itself

public Response createUpdateDeleteManualClinicalData(JSONObject json)

解决方法:我可以将数据获取为纯文本并将其转换为json.但是这是我要避免的开销.

Work around: I can get data as plain text and convert that to json. But its an overhead from my side which I want to avoid.

我愿意使用任何Json库(例如JsonNode等),只要我直接获得Json对象的结构,而不会从我这边给Json带来String的开销.这应该是常见用法,还是我在这里缺少一些核心概念.

I am open to using any Json library like JsonNode etc... as far as I get Json object Structure directly without the overhead of String to Json from my side. This should be common usage or am I missing some core concept here.

推荐答案

这是一个直接的解决方案,但我碰巧忽略了……我的错. 泽西岛比我想象的还要聪明...好奇地知道在层层下发生了什么魔术

It was a straight solution that I happened to overlooked... my bad. Jersey is way smarter than I thought... curious to know what magic happens under the layers

@POST
 @Consumes(application/json)
 @Produces(application/json)
 public Response createUpdateDeleteManualClinicalData(JsonNode jsonNode) {
//jsoNode body casted automatically into JsonNode
}

这篇关于在Jersey Rest Service中将Json请求作为Json对象使用的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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