MappingJackson2 Convert to date format

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.