import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;

import java.util.Objects;

/**
 * @author hrui
 * @date 2024/1/5 15:39
 */
public class Test2 {
    public String getName(){
        return "test";
    }

    public void setName2(String name){
        System.out.println("调用了方法 setName2,name值="+name);
    }

    public void setName(String name){
        System.out.println("调用了方法 setName,name值="+name);
    }
    public static void main(String[] args) {
        Test2 test2=new Test2();
        System.out.println(JSON.toJSONString(test2));

        System.out.println(JSON.parseObject("{\"name\":\"test\"}", Test2.class));

        Test3 test3=new Test3();
        test3.setName3("aaa");
        System.out.println(JSON.toJSONString(test3));

        Test4 test4=new Test4();
        System.out.println(JSON.toJSONString(test4, SerializerFeature.WriteMapNullValue));
    }
}
@Data
class Test3 extends Test2{
    private String name3;
    private String name4;

}
@Data
class Test4{
    private String name5;
    private String name6;
}

JSON实体类子类继承测试Demo-LMLPHP

01-07 02:35