GSON and jsongson for JSON Conversion

Source: Internet
Author: User

GSON and jsongson for JSON Conversion

During daily coding, you must record the simple usage of GSON when converting json data:

First, introduce the JAR package of Gson,

With the jar package, you can safely use it.

Gson can be used to convert many things, including list, map, set, and an object. However, gson must be used to convert data in some formats,

For example, if the date format is incorrect, record the gson conversion date format in detail.

My User object has a date-format birth. When converting the User list set, if not processed, the json is directly converted, as shown below:

This is the json data format obtained without processing:

Obviously this is not what we want, so what should we do? See the following:

The displayed result is. You only need to modify the parameters in setDateFormat ("yyyy-MM-dd") to achieve the desired effect.

Well, this is now.

 

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.