In Spring3.0 before most will use Mappingjackson JSON format data conversion, Spring3.0 later in the use of MappingJackson2 JSON format data conversion, but MappingJackson2 if not the date Format data to be processed, the data passed to the foreground is a Long type of data.
There are many ways to convert the date format of MappingJackson2 on-line, the Jackson2 comes with annotations, and the transformation through the configuration XML, I have tested each, through the configuration of XML through the Objectmapper change to achieve the purpose, However, the problem is that transmitting strings to the foreground automatically adds a slash to the data, which is not the case if all of the objects are being passed. But sometimes it is unavoidable to pass strings to the foreground. It's very uncomfortable to look at the slash.
I am now using the Objectmapper object to make a tool class that forwards all objects to strings as they go back. The code is as follows:
public static String Objectconvertstringfordate (Object object) {
try {
DateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Jsonmap.setdateformat (SDF);
return Jsonmap.writevalueasstring (object);
} catch (Jsonprocessingexception e) {
E.printstacktrace ();
}
return null;
}
If there's something wrong, I hope you correct.
MappingJackson2 Convert to date format