fastjson 下划线开头,且字段中含有下划线,这种字段parse的时候一直是null

jyztefdp  于 2021-11-27  发布在  Java
关注(0)|答案(1)|浏览(323)

class demo {

private String test;
private String _test_test;

public String get_test_test () {
return _test_test;
}

public void set_test_test (String _test_test) {
this._test_test = _test_test;
}

public String getTest () {
return test;
}

public void setTest (String test) {
this.test = test;
}
}

_test_test字段parse的时候,始终是null

7gyucuyw

7gyucuyw1#

class Demo {
            private String test;
            private String _test_test;

            public String get_test_test () {
                return _test_test;
            }

            public void set_test_test (String _test_test) {
                this._test_test = _test_test;
            }

            public String getTest () {
                return test;
            }

            public void setTest (String test) {
                this.test = test;
            }
        }
        Demo demo = new Demo();
        demo.setTest("TEST");
        demo.set_test_test("TEST_TEST");
        String text = JSON.toJSONString(demo);
        Demo obj = JSON.parseObject(text, Demo.class);
        Assert.assertEquals("TEST",obj.getTest());
        Assert.assertEquals("TEST_TEST",obj.get_test_test());

我按照你的例子试了下,没有问题,fastjson 1.2.36

相关问题