我想記錄所有將以json格式的傳入請求。我使用spring @RestController和@RequestBody註釋將傳入的json內容綁定到java對象。但我想將這些請求記錄到記錄器文件中。我有搜索周圍的objectmapper和jacksonbinding。如何使用restcontroller在spring restful webservice中記錄傳入的json請求?
@RestController
public class restClassName{
@RequestMapping(value={"/uri"})
public ObjectResponse functionRestName(@RequestBody ObjectRequest or){
String jsonInString = mapper.writeValueAsString(staff);//Redundant stuff as the request json is already read by MappingJackson2HttpMessageConverter
logger.info("request::"+jsonInString)
return instance;
}
}
但是,這似乎是doing.Since MappingJackson2HttpMessageConverter的rendundant方式已經讀取的HttpRequest以JSON請求轉換成Java object.I只需登錄該JSON MappingJackson2HttpMessageConverter將請求轉換成JSON到Java對象之前。