add compatible with JavaBean

This commit is contained in:
wenshao
2013-07-27 02:23:44 +08:00
parent 9a175bb3bb
commit cf6eaad3ad
4 changed files with 119 additions and 3 deletions
@@ -0,0 +1,50 @@
package com.alibaba.json.bvt.parser;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.util.TypeUtils;
public class TypeUtilsTest_compatibleWithJavaBean extends TestCase {
private boolean origin_compatibleWithJavaBean;
protected void setUp() throws Exception {
origin_compatibleWithJavaBean = TypeUtils.compatibleWithJavaBean;
TypeUtils.compatibleWithJavaBean = true;
}
protected void tearDown() throws Exception {
TypeUtils.compatibleWithJavaBean = origin_compatibleWithJavaBean;
}
public void test_true() throws Exception {
String text = JSON.toJSONString(new VO(123));
Assert.assertEquals("{\"ID\":123}", text);
Assert.assertEquals(123, JSON.parseObject(text, VO.class).getID());
}
public static class VO {
private int id;
public VO(){
}
public VO(int id){
this.id = id;
}
public int getID() {
return id;
}
public void setID(int id) {
this.id = id;
}
}
}
@@ -0,0 +1,50 @@
package com.alibaba.json.bvt.parser;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.util.TypeUtils;
public class TypeUtilsTest_compatibleWithJavaBean_boolean extends TestCase {
private boolean origin_compatibleWithJavaBean;
protected void setUp() throws Exception {
origin_compatibleWithJavaBean = TypeUtils.compatibleWithJavaBean;
TypeUtils.compatibleWithJavaBean = true;
}
protected void tearDown() throws Exception {
TypeUtils.compatibleWithJavaBean = origin_compatibleWithJavaBean;
}
public void test_true() throws Exception {
String text = JSON.toJSONString(new VO(true));
Assert.assertEquals("{\"ID\":true}", text);
Assert.assertEquals(true, JSON.parseObject(text, VO.class).isID());
}
public static class VO {
private boolean id;
public VO(){
}
public VO(boolean id){
this.id = id;
}
public boolean isID() {
return id;
}
public void setID(boolean id) {
this.id = id;
}
}
}