Idea Debug 时 JAVA对象转Json字符串 的操作

Idea Debug 时 JAVA对象转Json字符串 的操作

      • 正常操作
      • 高级操作

用Idea很多年了,功能很多,常用的不多,这里介绍个实用的功能:

正常操作

查看某个实体对象的值,若在debug时选中对象直接复制,那得到的会是如下结果:
Idea Debug 时 JAVA对象转Json字符串 的操作_第1张图片

DcUcEmployeeVo(picIds=[CsCommonAttachmentRelation(id=3281, attachId=null, relatedTableType=null, relatedTableId=null, downloadNum=null, sortOrder=null, createdDate=null, createdBy=null, lastUpdatedDate=null, lastUpdatedBy=null, removeFlag=null), CsCommonAttachmentRelation(id=3283, attachId=null, relatedTableType=null, relatedTableId=null, downloadNum=null, sortOrder=null, createdDate=null, createdBy=null, lastUpdatedDate=null, lastUpdatedBy=null, removeFlag=null)], picUrls=[], files=null, picUrl=, account=, plainPassword=null, roleId=4, roleName=null, organization=null, orgId=null, post=null, sexText=null, typeText=null, statusText=null, statusFlagText=null, code=null, createByText=null, updateByText=null, idAddressRegionPath=, idAddressRegionPathText=北京市北京市东城区, liveAddressRegionPath=, liveAddressRegionPathText=广东省深圳市南山区, employeeOrganizationList=[DcUcUserOrgVo(organization=null, post=null, active=null), DcUcUserOrgVo(organization=null, post=null, active=null), DcUcUserOrgVo(organization=null, post=null, active=null), DcUcUserOrgVo(organization=null, post=null, active=null)], verifyCode=454467, kw=null, flag=null, expandJson={})

复制出来的结构基本都是 key=value 的格式,不仅不方便查看,也不方便取值复制已经提供文档啥的。

高级操作

在debug在停在断点处时,将光标定位在指定实体对象处,按快捷键Alt+F8 ,会出来Evaluate 的弹框,在Expression 下的输入框处输入Java代码(例如JsonObject.toJsonString(对象)),点击底部Evaluate,然后view出来的结果:
Idea Debug 时 JAVA对象转Json字符串 的操作_第2张图片
得到的结果就是我们想要的Json字符串。最后随便找个在线格式化的网站就得到我们想要的标准Json格式数据;

例如 http://json.cn/#

Idea Debug 时 JAVA对象转Json字符串 的操作_第3张图片

你可能感兴趣的:(技术干货,java,json,idea)