fastjson JSONType#ignores not working on "isXxx" java bean properties

v7pvogib  于 3个月前  发布在  Java
关注(0)|答案(1)|浏览(64)

com.alibaba.fastjson.annotation.JSONType#ignores does not work during serializing java beans to JSONs when there are some public boolean isXxx() methods. Test codes are listed below:

@JSONType(ignores = {"xxx", "yyy"})
public class Test {

    public boolean isXxx() {
        return true;
    }
    public boolean getYyy() {
        return true;
    }
    public boolean getZzz() {
        return true;
    }
    public static void main(String[] args) {
        Object json = JSON.toJSON(new Test());
        System.out.println("Expected: {\"zzz\":true}");
        System.out.println("  Actual: " + json);
    }
}
fjnneemd

fjnneemd1#

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;

@jsontype(ignores = {"yyy"})
public class Test {

@JSONField(serialize = false)
public boolean isXxx() {
    return true;
}

public boolean getYyy() {
    return true;
}

public boolean getZzz() {
    return true;
}

public static void main(String[] args) {
    Object json = JSON.toJSON(new Test());
    System.out.println("Expected: {\"zzz\":true}");
    System.out.println("  Actual: " + json);
}

}

相关问题