Self-digging pit own jump jsonmappingexception: (was java.lang.NullPointerException) (through reference chain:)

Source: Internet
Author: User

In Web projects, we often design javabean that correspond to the interface as an entity, and in order to be compatible with the null values passed in from the foreground, some fields will be wrapped instead of the basic type. But often my entity has been designed to complete, many times we will change the original entity based on the field return value type, rather than delete the rewrite. So the question came, and some of the careless students changed the basic type of the attribute (such as long) to a wrapper type (such as long) without modifying the Setter/getter type.

This situation will give an error, and the error of the report often makes people feel confused. The following is a case of an error that occurs when the entity is serialized as a JSON string using Com.fasterxml.jackson:

Com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: student["Sid"])

My entity is as follows:

public class Student {private Long sid;private String name;public long GetSID () {return SID;} public void Setsid (long sid) {this.sid = SID;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;}}

This type of entity will be reported in different cases of different errors, this article only lists this one situation, followed by supplementary.

Share!

Edit by Jimmy

2014.09.18

Self-digging pit own jump jsonmappingexception: (was java.lang.NullPointerException) (through reference chain:)

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.