package com.linyf.demo.fastjson;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class JsonBean {
private String name;
private Integer age;
public String getJsonString(){
return JSONObject.toJSONString(this);
}
class Test{
public static void main(String[] args) {
String jsonString = "{\"name\":\"zhangsan\",\"age\":\"18\"}";
JsonBean jsonBean = JSONObject.parseObject(jsonString, JsonBean.class);
System.out.println(jsonBean);
String jsonString1 = jsonBean.getJsonString();
System.out.println(jsonString1);
package com.linyf.demo.fastjson;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class JsonBean {
private String name;
private Integer age;
public String getJsonString(){
return JSONObject.toJSONString(this);
}
}
class Test{
public static void main(String[] args) {
String jsonString = "{\"name\":\"zhangsan\",\"age\":\"18\"}";
JsonBean jsonBean = JSONObject.parseObject(jsonString, JsonBean.class);
System.out.println(jsonBean);
String jsonString1 = jsonBean.getJsonString();
System.out.println(jsonString1);
}
}