Get the App
SLTechnology News&Howtos  ›  Development  › 

The JSON.toJSONString () empty field does not ignore how to modify it.

Shulou Source: shulou.com Published: 2022-06-01 19:27:07 10月12日 Update

This article mainly introduces the JSON.toJSONString () empty field does not ignore how to modify the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this JSON.toJSONString () empty field does not ignore how to modify the article will have something to gain, let's take a look.

JSON.toJSONString () empty field does not ignore modification

Using the JSON.toJSONString (object) method, the fields that are empty by default are automatically ignored in the returned json.

Public static void main (String [] args) {DossierApply dossierApply = new DossierApply (); String s = JSON.toJSONString (dossierApply, valueFilter); System.out.println (s);} private static ValueFilter valueFilter = (o, s, o1)-> o1 = = null? ": o1

After adding this filter, all null and "" strings are converted to "" values and output to the string.

Description of JSON.toJSONString () missing / few fields problem

Use the JSON.toJSONString () method to convert the object to JSON format, but the result is missing a field.

Reason

The JSON method does not recognize the setter,getter method

My field is "uId"

Because my entity is automatically generated by generator mybatis, the generated setter,getter is as follows:

Public Long getuId () {return uId;} public void setuId (Long uId) {this.uId = uId;}

Add another set of setter,getter, not modify it, repeat three:

Public void setUId (Long uId) {this.uId = uId;} public Integer getDtId () {return dtId;} on "JSON.toJSONString () empty fields do not ignore how to modify" this article is introduced here, thank you for reading! I believe that everyone has a certain understanding of the knowledge of "JSON.toJSONString () empty field do not ignore how to modify". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Fields methods knowledge content articles generation value reasons characters strings entities objects easy to operate articles easy to understand are made up of more formats see results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker OPPO Reno Shulou Tech Info Shulou Information