Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved BeanToArray parse & add testcase
- Loading branch information
Showing
8 changed files
with
280 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_Object_2_public.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_Object_public.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_double_private.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.alibaba.json.bvt.writeAsArray; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONException; | ||
import com.alibaba.fastjson.parser.Feature; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class WriteAsArray_double_private extends TestCase { | ||
public void test_0 () throws Exception { | ||
VO vo = new VO(); | ||
vo.setId(123D); | ||
vo.setName("wenshao"); | ||
|
||
String text = JSON.toJSONString(vo, SerializerFeature.BeanToArray); | ||
Assert.assertEquals("[123,\"wenshao\"]", text); | ||
|
||
VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean); | ||
Assert.assertTrue(vo.id == vo2.id); | ||
Assert.assertEquals(vo.name, vo2.name); | ||
} | ||
|
||
public void test_error() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[123.A,\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
public void test_error1() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[\"A\",\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
public void test_error2() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[123:\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
public static class VO { | ||
private double id; | ||
private String name; | ||
|
||
public double getId() { | ||
return id; | ||
} | ||
|
||
public void setId(double id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_float2_private.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.alibaba.json.bvt.writeAsArray; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONException; | ||
import com.alibaba.fastjson.parser.Feature; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class WriteAsArray_float2_private extends TestCase { | ||
public void test_0 () throws Exception { | ||
VO vo = new VO(); | ||
vo.setId(123F); | ||
vo.setName("wenshao"); | ||
|
||
String text = JSON.toJSONString(vo, SerializerFeature.BeanToArray); | ||
Assert.assertEquals("[123,\"wenshao\"]", text); | ||
|
||
VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean); | ||
Assert.assertTrue(vo.id == vo2.id); | ||
Assert.assertEquals(vo.name, vo2.name); | ||
} | ||
|
||
public void test_error() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[123.A,\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
public void test_error1() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[\"A\",\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
public void test_error2() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[123:\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
private static class VO { | ||
private float id; | ||
private String name; | ||
|
||
public float getId() { | ||
return id; | ||
} | ||
|
||
public void setId(float id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_float2_public.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.alibaba.json.bvt.writeAsArray; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONException; | ||
import com.alibaba.fastjson.parser.Feature; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class WriteAsArray_float2_public extends TestCase { | ||
public void test_0 () throws Exception { | ||
VO vo = new VO(); | ||
vo.setId(123F); | ||
vo.setName("wenshao"); | ||
|
||
String text = JSON.toJSONString(vo, SerializerFeature.BeanToArray); | ||
Assert.assertEquals("[123,\"wenshao\"]", text); | ||
|
||
VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean); | ||
Assert.assertTrue(vo.id == vo2.id); | ||
Assert.assertEquals(vo.name, vo2.name); | ||
} | ||
|
||
public void test_error() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[123.A,\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
public void test_error1() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[\"A\",\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
public void test_error2() throws Exception { | ||
Exception error = null; | ||
try { | ||
JSON.parseObject("[123:\"wenshao\"]", VO.class, Feature.SupportArrayToBean); | ||
} catch (JSONException ex) { | ||
error = ex; | ||
} | ||
Assert.assertNotNull(error); | ||
} | ||
|
||
public static class VO { | ||
private float id; | ||
private String name; | ||
|
||
public float getId() { | ||
return id; | ||
} | ||
|
||
public void setId(float id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |