|
| 1 | +package com.alibaba.json.bvt.issue_1200; |
| 2 | + |
| 3 | +import com.alibaba.fastjson.JSON; |
| 4 | +import com.alibaba.fastjson.annotation.JSONField; |
| 5 | +import com.alibaba.json.bvt.bug.Bug_101_for_rongganlin_case2; |
| 6 | +import junit.framework.TestCase; |
| 7 | +import org.apache.commons.beanutils.BeanUtils; |
| 8 | + |
| 9 | +import java.util.Map; |
| 10 | + |
| 11 | +/** |
| 12 | + * Created by kimmking on 09/06/2017. |
| 13 | + */ |
| 14 | +public class Issue1254 extends TestCase { |
| 15 | + public void test_for_issue() throws Exception { |
| 16 | + A a = new A(); |
| 17 | + a._parentId = "001"; |
| 18 | + String test = JSON.toJSONString(a); |
| 19 | + System.out.println(test); |
| 20 | + assertEquals("{\"_parentId\":\"001\"}", test); |
| 21 | + |
| 22 | + B b = new B(); |
| 23 | + b.set_parentId("001"); |
| 24 | + |
| 25 | + |
| 26 | +// Object o = BeanUtils.getProperty(b,"_parentId"); |
| 27 | +// System.out.println(o); //test ok, println 001 |
| 28 | +// |
| 29 | +// //BeanUtils.getProperty(b,"parentId"); //java.lang.NoSuchMethodException: Unknown property 'parentId' on class 'class com.alibaba.json.bvt.issue_1200.Issue1254$B' |
| 30 | + |
| 31 | + String testB = JSON.toJSONString(b); |
| 32 | + System.out.println(testB); |
| 33 | + assertEquals("{\"_parentId\":\"001\"}", testB); |
| 34 | + |
| 35 | + } |
| 36 | + |
| 37 | + public static class A { |
| 38 | + public String _parentId; |
| 39 | + } |
| 40 | + |
| 41 | + public static class B { |
| 42 | + private String _parentId; |
| 43 | + |
| 44 | + public String get_parentId() { |
| 45 | + return _parentId; |
| 46 | + } |
| 47 | + |
| 48 | + public void set_parentId(String _parentId) { |
| 49 | + this._parentId = _parentId; |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments