日志里toString的类,怎么再转回成bean实例类对象?debug调试用。

kingmax54212008 2019-03-09 08:44:48
日志里toString的类,怎么再转回成bean实例类对象?debug调试用。 一般有通用的方法么,大虾们怎么搞法的?

把对象打印到日志toString结果如下:

shopGoodsBuyerParamDto = ShopGoodsBuyerParamDto {shopId=44, goodsCodeList=[20000890, 20000989, 20001017, 20000887, 20000956, 20000879, 20000880, 20001182, 20001186, 20001190, 20001174, 20001178, 20000617]}, buyer = Buyer{id=1234, name='张三', cityId=310100}


一般怎么把这个对象返回到java bean的Entity,一般什么实现这个entityStringToEntity方法?


类定义如下:

public class ShopGoodsBuyerParamDto {

Integer shopId;
List<Integer> goodsCodeList;
Buyer buyer;

public Integer getShopId() {
return shopId;
}

public void setShopId(Integer shopId) {
this.shopId = shopId;
}

public List<Integer> getGoodsCodeList() {
return goodsCodeList;
}

public void setGoodsCodeList(List<Integer> goodsCodeList) {
this.goodsCodeList = goodsCodeList;
}

public Buyer getBuyer() {
return buyer;
}

public void setBuyer(Buyer buyer) {
this.buyer = buyer;
}

@Override
public String toString() {
return "ShopGoodsBuyerParamDto{" +
"shopId=" + shopId +
", goodsCodeList=" + goodsCodeList +
", buyer=" + buyer +
'}';
}
}



public class Buyer {

Integer id;
String name;
Integer cityId;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Integer getCityId() {
return cityId;
}

public void setCityId(Integer cityId) {
this.cityId = cityId;
}

@Override
public String toString() {
return "Buyer{" +
"id=" + id +
", name='" + name + '\'' +
", cityId=" + cityId +
'}';
}
}
...全文
2143 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
biankobe24 2021-04-30
  • 打赏
  • 举报
回复
3楼正解,fastjson可以考虑换成Jackson或者Gson
weixin_47371659 2021-04-30
  • 打赏
  • 举报
回复
解决没有,我也遇到同样的需求
大隐藏于寺 2019-03-10
  • 打赏
  • 举报
回复 1
你可以在toString()的时候用类似fastjson的框架输出标准的json,后面也可以用对应的方法解析这个json字符串为对象
kingmax54212008 2019-03-09
  • 打赏
  • 举报
回复
引用 1 楼 大隐藏于寺 的回复:
看不懂你想问什么
就类似于序列化、反序列化的概念。 我的一个对象.toString()变成了字符串: shopGoodsBuyerParamDto = ShopGoodsBuyerParamDto {shopId=44, goodsCodeList=[20000890, 20000989, 20001017, 20000887, 20000956, 20000879, 20000880, 20001182, 20001186, 20001190, 20001174, 20001178, 20000617]}, buyer = Buyer{id=1234, name='张三', cityId=310100} 现在我想把这个字符串反转为对象。
大隐藏于寺 2019-03-09
  • 打赏
  • 举报
回复
看不懂你想问什么

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧