Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report