使用通用JSON对象作为请求主体 [英] Using generic JSON Object as Request Body

查看:82
本文介绍了使用通用JSON对象作为请求主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器,该控制器接收JSON对象作为输入.但是问题在于,JSON的内容会因不同的请求而有所不同,因此Im无法将RequestBody映射到POJO.
有没有一种方法可以将输入参数指定为通用JSONObject,而不必指定特定的POJO.
我尝试了@RequestBody JSONObject inputJson.但这从客户端抛出了错误的请求.
我将Spring 3.2.13和Angular用作前端.
任何帮助深表感谢.谢谢.

I'm having a controller which receives JSON Object as input. But the problem is that, the content of JSON will vary for different requests, so Im not able to map the RequestBody to a POJO.
Is there a way I can specify the input parameter as generic JSONObject without having to specify a specific POJO.
I tried @RequestBody JSONObject inputJson. But this is throwing bad request from the client side.
I'm using spring 3.2.13 and Angular as Front End.
Any help is much appreciated. Thanks.

推荐答案

您是否尝试将JSON转换为字符串输入并转换回JSON?检查此线程.

Did you try to convert the JSON as a string input and convert back to JSON? Check this thread.

这篇关于使用通用JSON对象作为请求主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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