首先使用gson-2.8.6
下面是普通javaBean转json。
import com.google.gson.Gson; /** * @author yongjar * @date 2020/4/28 */ public class GsonTester { public static void main(String args[]) { Gson gson = new Gson(); Bean bean = new Bean(); bean.setStatus("1"); bean.setMessage("success info"); //普通的javaBean转json String json = gson.toJson(bean); System.err.println(json); } } class Bean { private String status; private String message; public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }