Simple use of Jackson's Annotation

Source: Internet
Author: User

@ Jsonautodetect (class)

This is the annotation acting on the class. It is mainly used to indicate that the class uses annotation, and can automatically detect getter, setter, and constructor to generate a JSON object.

@ Jsonignore (method/Field): it acts on a method or field to indicate that the method or field with this annotation is ignored when JSON is generated.

 

Example:

@ Entity @ cache (usage = cacheconcurrencystrategy. read_write) @ jsonautodetect/*** here mark attributes that do not generate a JSON object. Here I mark two attributes as one hibernatelazyinitializer attribute. Why do I mark this attribute? refer to the previous blog post, A Password attribute cannot be converted to a JSON object due to security reasons. After all, JSON is called at the front end. * if you want to ignore an attribute during conversion, you can add */@ jsonignoreproperties (value = {"hibernatelazyinitializer", "password"}) public class user {private long ID; private string name; private string password; private string email; private date createat; @ ID @ generatedvalue (Strategy = generationtype. identity) Public long GETID () {return ID;} public void setid (long ID) {This. id = ID;}/*** convert the output format of the date object. For the customdateserializer code, refer to the previous blog post */@ jsonserialize (using = customdateserializer. class) Public date getcreateat () {return createat;} public void setcreateat (date createat) {This. createat = createat;}/*** other getter and setter are omitted */}

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.