假设我有:
ReportExecution executionRequestBody = new ReportExecution();
我需要一些东西来解析实例,使其以 JSON 格式解析,但具有文本前景。
String b = JacksonParserParse(executionRequestBody);
我可以做这样的事情:
logger.info(b);
输出:
{"reportUnitUri": "/path/to/report",
"async": "true",
"freshData": "false",
"saveDataSnapshot": "false",
"outputFormat": "html",
"interactive": "true",
"ignorePagination": "false",
"pages": "1-5"
}
最终的任务是简单地将此字符串插入到 Spring RestTemplate HttpEntity 中的 HTTP 请求正文中。
因此,如果有不那么棘手的方法,我非常乐意听到替代方案。
现在我可以进行简单的映射,但这通常会在文件系统中生成 .json 文件,我真的不知道如何将其插入到我的 HttpEntity
中。
最佳答案
您想要做的是将 RestTemplate 与 Jackson 集成。这可以轻松完成,并在 this 中进行了描述。所以问题。
关于java - 如何通过 Jackson Parser 从 Java 实例返回 String 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22813538/