Resttemplate-请求pojo本身或请求json字符串并解析它 [英] Resttemplate - request the pojo itself or request the json string and parse it

查看:316
本文介绍了Resttemplate-请求pojo本身或请求json字符串并解析它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个选择:

请求对象

restTemplate.exchange(url, HttpMethod.GET, entity, Object.class);

或请求JSON

restTemplate.exchange(url, HttpMethod.GET, entity, String.class);

然后解析它.

幕后两个都将使用JSON,但是是否有任何约定或最佳实践?

Behind the scenes both will be using JSON, but is there any convention or best practice?

推荐答案

您可以为相应的json创建java对象,然后响应将自动序列化:

You can create java object for corresponding json then response will be serialized automatically:

restTemplate.exchange(url, HttpMethod.GET, entity, MyResponseBean.class);

对于Java Bean生成, jsonschema2pojo 是有用的.

For java bean generation jsonschema2pojo is usefull.

这篇关于Resttemplate-请求pojo本身或请求json字符串并解析它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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