Hi,
I've coded a exception handler in my project to format all json response. like this:
this code will wrap user object to a response message, which has a status info and a message info.Code:public @ResponseBody ResponseMessage save(final User user){ ResponseMessage rm = ResponseMessage.handleException( new handler(){ // this is a interface. return userRepository.save(user); // this is a repository object, which may throw exceptions. } ); return rm; }
or exception:Code:{ status:'success', message:{id:'1',username:'jmars'} }
So I got lots of the same code fragments, response message script, in my project.Code:{ status:'warning', message:{code:'e002',message:'The database can't be connected.'} }
I wonder if there is a way to simplify this process, so that people do not need to code the message transformation explicitly. It might be an aop, interceptor, filter, controller post processor, or view resolver, something else.
Jan


Reply With Quote
