Return JSON format does not ignore null fields

Source: Internet
Author: User
Tags tojson

return JSON format does not ignore null fieldsPosted 353 days ago Author king666 271 views Copy previous post next postTags: json

Title, if a field of an entity is null, after the JSON is turned, there is no such property, what settings are required to display the empty data field

11 replies.
Wendal 1/F • 353 days ago
@Ok("json:full")
king666 (QQ_640D75E3) 2 floor • 353 days ago

Are @wendal added to the corresponding field or entity, or is it?


Wendal 3/F • 353 days ago

Isn't @qq_640d75e3 talking about the return of the Ingress method?

king666 (QQ_640D75E3) 4 floor • 353 days ago

@wendal the entity class

king666 (QQ_640D75E3) 5 floor • 353 days ago

@wendal like Jackson's @jsoninclude.


Wendal 6/F • 353 days ago

Entity does not have this configuration

Json.tojson method.

Json.toJson(obj, JsonFormat.full());
king666 (QQ_640D75E3) 7 floor • 353 days ago

@wendal personally think Nutz need to pay attention to https://nutz.cn/yvr/t/7fmfpb9oguivrqck7add0u7i1r this problem

fengjidong1991 8/F • 212 days ago

I added the @ok ("Json:full") after the null field is still not displayed


Wendal 9/F • 212 days ago

@fengjidong1991 on the Code

fengjidong1991 10/F • 212 days ago

@IocBean
@Ok ("Json:full")
@Fail ("http:500")
@At ("/facmanagecar")
public class Facmanagercarmodule extends basemodule{

@Atpublic Object Queryfacmanagecar (facmanagecarreq req) {Facmanagecarresp resp = new Facmanagecarresp ();    Pager Pager = Dao.createpager (req.page,20);    Cnd where = Cnd.new ();       Where.and ("Facid", "=", Req.factoryid);    if (req.carstatus==1) {Where.and ("carstatus", "=", false);    }else if (req.carstatus==2) {Where.and ("carstatus", "=", true);    }//Vehicle grade if (Strings.isnotblank (req.carlicence)) {Where.and ("carlicence", "like", "%" +req.carlicence+ "%");    }//Owner's mobile number if (Strings.isnotblank (Req.cellphone)) {Where.and ("CellPhone", "like", "%" +req.cellphone+ "%");    }//Owner's name if (Strings.isnotblank (Req.realname)) {Where.and ("Realname", "like", "%" +req.realname+ "%");    }//Maintenance expires if (req.carnexttime!=null) {Where.and ("Carnexttime", "<=", req.carnexttime);                }//Insurance expires if (req.insuranceenddate!=null) {Where.and ("insuranceenddate", "<=", req.insuranceenddate); }//Annual inspection expiry if (req.checkenddate!=null) {wheRe.and ("Checkenddate", "<=", req.checkenddate);    }//Sort by field name if (Req.sorttype = = null) {Where.orderby ("createtime", "desc");  } else {Where.orderby ("convert (" + req.sortType.getName () + "using GBK)", "" + req.sortType.getSorts () +    "");    } List <FacManageCarView> Fmcvs = Dao.query (Facmanagecarview.class, Where,pager);    int Count =dao.count (facmanagecarview.class,where); if (fmcvs==null| |        Fmcvs.size () ==0) {resp.requestcode=-1;    Return resp;    } list<facmanagecarentity> fmces = new arraylist<facmanagecarentity> ();    List<dictionary> DCS = Dao.query (Dictionary.class,cnd.where ("type", "=", "Car_state"));            for (int i=0;i<fmcvs.size (); i++) {facmanagecarentity fmce = new facmanagecarentity (); Fmce.       Snumber = (req.page-1) *20+i+1;//ordinal value assignment int code;       if (Fmcvs.get (i). Iscarstatus () ==false) {code = 1;       }else{code = 2; } for (int j=0;j<dcs.size (); j + +) {if (Dcs.get (j). Getval () Equals ("" +code)) {Fmce.carstatusdesc = Dcs.get (j). GetItems ();//Vehicle Status Description         Break       }} FMCE.FMCV = Fmcvs.get (i);    Fmces.add (FMCE);    } pager.setrecordcount (count);    Resp.pagecount = Pager.getpagecount ();    Resp.count = count;    Resp.fmces = fmces;          Return resp;    } @Atpublic Object Fetchfacmanagecar (facmanagecarreq req) {Facmanagecarresp resp = new Facmanagecarresp (); Vehicle ID if (req.       id<=0) {resp.requestcode=-1;    Return resp; } Facmanagecarview FMCV = Dao.fetch (Facmanagecarview.class,cnd.where ("id", "=", req.    ID));       if (fmcv==null) {resp.requestcode=-1;    Return resp;    } facmanagecarentity fmce = new facmanagecarentity ();    FMCE.FMCV = FMCV;    int code;    if (Fmcv.iscarstatus () ==false) {code = 1;    }else{code = 2;    } Dictionary dc = Dao.fetch (Dictionary.class,cnd.where ("type", "=", "Car_state"). and ("Val", "=", code)); Fmce.carstatusdesc = Dc.getitems ();//Vehicle usage status Description resp.requestcode=0;    RESP.FMCE = FMCE; Return resp;}    @Atpublic Object Queryfacmanagerecord (facmanagecarreq req) {Facmanagecarresp resp = new Facmanagecarresp ();    Pager Pager = Dao.createpager (Req.page, 20);       if (req.carid<=0) {resp.requestcode =-1;    Return resp;    } Cnd where = Cnd.where ("Carid", "=", Req.carid);    if (Req.sorttype = = null) {Where.orderby ("createtime", "desc");  } else {Where.orderby ("convert (" + req.sortType.getName () + "using GBK)", "" + req.sortType.getSorts () +    "");    } list<repairrecord> RRs = Dao.query (Repairrecord.class,where,pager); if (rrs==null| |       Rrs.size () ==0) {Resp.requestcode =-1;    Return resp;    } int count = Dao.count (Repairrecord.class,where);    Pager.setrecordcount (count);    list<facmanagerepairrecordentity> fmrres = new arraylist<facmanagerepairrecordentity> (); List<dictionary> dr = Dao.query (DICTIONARY.CLASS,CND.WHere ("type", "=", "Repairrecord_type"));       for (int i=0;i<rrs.size (); i++) {facmanagerepairrecordentity Fmrre = new facmanagerepairrecordentity ();       FMRRE.RR = Rrs.get (i); Fmrre.       Snmuber = (req.page-1) *20+i+1; for (Dictionary d:dr) {if (D.getval (). Equals ("" +rrs.get (i). GetType () +1)) {Fmrre.typedesc = D.getitems ();    /maintenance record type description}} fmrres.add (Fmrre);    } resp.requestcode=0;    Resp.fmrres = Fmrres;    Resp.count = count;    Resp.pagecount = Pager.getpagecount (); Return resp;} /** * Maintenance Project Interface * @author FJD * @param req * @return */@Atpublic Object queryfacmanageorderitme (facmanageorderitmereq req)    {Facmanageorderitmeresp resp = new Facmanageorderitmeresp ();       if (req.id<=0) {resp.requestcode =-1;    Return resp;           } list<orderitme> ois = Dao.query (Orderitme.class, Cnd.where ("Rrid", "=", req.id)); if (ois==null| |       Ois.size () ==0) {resp.requestcode =-1;    Return resp; } int count =  Dao.count (Orderitme.class,cnd.where ("Rrid", "=", req.id));    list<facmanageorderitmeentity> fmoies = new arraylist<facmanageorderitmeentity> ();    list<dictionary> dlist = Dao.query (Dictionary.class,cnd.where ("type", "=", "Repairrecord_type"));       for (int i=0;i<ois.size (); i++) {facmanageorderitmeentity Fmoie = new facmanageorderitmeentity ();       Fmoie.oi = Ois.get (i); Fmoie. Snumber = (req.page-1) *20+i+1;//serial number for (Dictionary d:dlist) {if (D.getval (). Equals ("" +ois.get (i). GetType ()))       {Fmoie.typedesc = D.getitems ();//Maintenance Record Description}}    Fmoies.add (Fmoie);    } Resp.count = count;    Resp.fmoies = fmoies; Return resp;}

}


Wendal 11/F • 212 days ago

It's so complicated, let's get a demo.

Return JSON format does not ignore null fields

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.