@ResponseBody
戻り値
[{"id":1010,"name":"projectname2"}]
json文字列を入力
しかし、次のjson文字列が必要です
[{"id":1010,"name":"projectname2","age":"21"}]
では、年齢属性をデフォルトの生成されたjson文字列に連結するにはどうすればよいですか?
spring-json jarでJava spring-mvcフレームワークを使用しています
@RequestMapping(value = "/projectsByEmployeeId/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Project> getProjectsByEmployeeId(
HttpServletRequest request) {
String filter = request.getParameter("filter");
FilterAttributes[] filterAttributes = null;
try {
filterAttributes = new ObjectMapper().readValue(filter,
FilterAttributes[].class);
} catch (Exception exception) {
logger.error("Filtering parameter JSON string passing failed",
exception);
}
if ((filterAttributes != null)
&& (!filterAttributes[0].getStringValue().isEmpty())) {
return utilityService.getProjectsByEmployeeId(44L);//this is an example id
} else {
return utilityService.getProjects();
}
}