Я использую jackson 2.9.8
и пытаюсь украсить свой json.
Код, который я использую:
protected void setSuccessMessage(HttpServletResponse response, JSONObject jObj) throws IOException {
// Set the status
response.setStatus(200);
// Create the response
response.setContentType("application/json");
PrintWriter out = response.getWriter();
jObj.put("success", 1);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
mapper.setVisibility(PropertyAccessor.ALL, Visibility.ANY);
out.print(mapper.writeValueAsString(jObj));
out.close();
}
Однако мой вывод имеет новыйmap
тег, который я не хочу.Вывод:
{
"map" : {
"success" : 1,
"documents_metata" : {
"myArrayList" : [ {
"map" : {
"documentType" : "PS_XML",
"patientId" : "x",
"effectiveTime" : "2019-05-08",
"author" : "xxx",
"repositoryId" : "xxx",
"id" : "xxx",
"title" : "xxx"
}
}, {
"map" : {
"documentType" : "PS_PDF",
"patientId" : "x",
"effectiveTime" : "2019-05-08",
"author" : "xxx",
"repositoryId" : "xxx",
"id" : "xxx",
"title" : "xxx"
}
} ]
}
}
}
Правильно должно быть:
{
"success": 1,
"documents_metadata": [
[
{
"documentType": "PS_PDF",
"patientId": "x",
"effectiveTime": "2019-05-08",
"author": "xxx",
"repositoryId": "xxx",
"id": "xxx",
"title": "xxx"
},
{
"documentType": "PS_XML",
"patientId": "x",
"effectiveTime": "2019-05-08",
"author": "xxx",
"repositoryId": "xxx",
"id": "xxx",
"title": "xxx"
}
]
]
}
JSON без jackson
в порядке, но не имеет отступ.Вы знаете, как это исправить?