當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
使用SpringBoot的jackson包进行实体类型转换
生活随笔
收集整理的這篇文章主要介紹了
使用SpringBoot的jackson包进行实体类型转换
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
1、將Java對象轉(zhuǎn)換為JSON
ObjectMapper mapper = new ObjectMapper(); Staff obj = new Staff();mapper.writeValue(new File("d:\\file.json"), obj);String jsonInString = mapper.writeValueAsString(obj);writeValue還支持的方法如下圖所示:
2、Jave實體類之間轉(zhuǎn)換
ObjectMapper mapper = new ObjectMapper(); String answer= "{'name' : 'mkyong'}"; CyAnswerTransport cyAnswerTransport = mapper.readValue(answer, CyAnswerTransport.class);readValue還支持的轉(zhuǎn)換方法如下圖所示:
3、字符串對象轉(zhuǎn)List對象
ObjectMapper mapper = new ObjectMapper(); String content = ""; List<CyAnswerDetail> answerDetailList = mapper.readValue(content,new TypeReference<List<CyAnswerDetail>>(){});?
轉(zhuǎn)載于:https://my.oschina.net/niithub/blog/1840452
總結(jié)
以上是生活随笔為你收集整理的使用SpringBoot的jackson包进行实体类型转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: nginx服务器绑定域名和设置根目录的方
- 下一篇: 密码协议(三)裁决协议和自动执行协议