object to 字符串json

 1 package com.beijxing.TestMain;
 2 
 3 import com.beijxing.entity.Student;
 4 import com.google.gson.Gson;
 5 import com.google.gson.annotations.SerializedName;
 6 
 7 /** 
 8 * 
 9 * @author 作者 : ywp
10 * @version 创建时间:2016年10月30日 下午9:21:33 
11 */
12 public class TestGson1 {
13     public static void main(String[] args) {
14         testGson();
15     }
16     public static void testGson(){
17         Student student = new Student();
18         student.setId(1);
19         student.setName("杨文培");
20         student.setSex("男");
21         //student.setAge(23);
22         student.setBirthday("1993-01-23");
23         Gson gson = new Gson();
24         System.out.println(gson.toJson(student));
25     }
26 }
原文地址:https://www.cnblogs.com/yangly/p/6014174.html