java里面object和string的相互转换

1. string 转 object

Type type = new TypeToken<Object>() {}.getType();
Object obj = GsonUtils.fromJson(strValue, type);

 

2. object转string

String strValue = (new ObjectMapper()).writeValueAsString(object);

 

扩展阅读:

Gson : https://www.cnblogs.com/majay/p/6336918.html

      https://www.jianshu.com/p/fc5c9cdf3aab

fastjson : https://www.w3cschool.cn/fastjson/fastjson-api.html

jackson : https://www.yiibai.com/jackson/

posted @ 2018-11-26 11:36  sunnyamy  阅读(27575)  评论(1编辑  收藏  举报