package com.jxufe.study.jsonstudy.test; import com.fasterxml.jackson.databind.ObjectMapper; import com.jxufe.study.jsonstudy.model.User; import com.jxufe.study.jsonstudy.model.OtherBean; import net.sf.json.JSONObject; import org.junit.Test; import java.io.IOException; import java.util.Date; /** * @author hong.zheng * @Description * @date 2017-12-08-11:26 * OtherJson { @Test public void jsonLibTest() { OtherBean otherBean = new OtherBean(); otherBean.setName("mindong"); JSONObject jsonObject = JSONObject.fromObject(otherBean); System.out.println(jsonObject.toString()); //{"name":"mindong","otherName":"getMethod"} 会调用 以Get开头的方法,生成Json } @Test public void jacksonTest() throws IOException { ObjectMapper objectMapper = new ObjectMapper(); OtherBean otherBean = new OtherBean(); otherBean.setName("xiaoting"); objectMapper.writeValue(System.out,otherBean); // 输出 {"name":"xiaoting","myName":"mindong"} 会调用 以Get开头的方法,生成Json } }
java Json 技术记录
标签:不能 isa 社区 long get hash row log java对象