This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
130 additions
and
0 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
src/test/java/com/alibaba/json/bvt/bug/Bug_for_issue_465.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,130 @@ | ||
package com.alibaba.json.bvt.bug; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.annotation.JSONField; | ||
import com.alibaba.fastjson.annotation.JSONType; | ||
import com.alibaba.fastjson.parser.Feature; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class Bug_for_issue_465 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
String json = "[\"abc\",\"efg\",\"sss\",[1,2]]"; | ||
|
||
TestBean testBean = JSON.parseObject(json, TestBean.class); | ||
Assert.assertEquals("abc", testBean.name); | ||
Assert.assertEquals("efg", testBean.country); | ||
Assert.assertEquals("sss", testBean.password); | ||
Assert.assertEquals(2, testBean.location.length); | ||
Assert.assertEquals(1, testBean.location[0]); | ||
Assert.assertEquals(2, testBean.location[1]); | ||
} | ||
|
||
public void test_for_issue_private() throws Exception { | ||
String json = "[\"abc\",\"efg\",\"sss\",[1,2]]"; | ||
|
||
TestBean1 testBean = JSON.parseObject(json, TestBean1.class); | ||
Assert.assertEquals("abc", testBean.name); | ||
Assert.assertEquals("efg", testBean.country); | ||
Assert.assertEquals("sss", testBean.password); | ||
Assert.assertEquals(2, testBean.location.length); | ||
Assert.assertEquals(1, testBean.location[0]); | ||
Assert.assertEquals(2, testBean.location[1]); | ||
} | ||
|
||
@JSONType(parseFeatures = Feature.SupportArrayToBean) | ||
public static class TestBean { | ||
private String name; | ||
|
||
private String password; | ||
|
||
private String country; | ||
|
||
private int[] location; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@JSONField(ordinal = 0) | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
@JSONField(ordinal = 2) | ||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
@JSONField(ordinal = 1) | ||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
|
||
public int[] getLocation() { | ||
return location; | ||
} | ||
|
||
@JSONField(ordinal = 3) | ||
public void setLocation(int[] location) { | ||
this.location = location; | ||
} | ||
} | ||
|
||
@JSONType(parseFeatures = Feature.SupportArrayToBean) | ||
private static class TestBean1 { | ||
private String name; | ||
|
||
private String password; | ||
|
||
private String country; | ||
|
||
private int[] location; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@JSONField(ordinal = 0) | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
@JSONField(ordinal = 2) | ||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public String getCountry() { | ||
return country; | ||
} | ||
|
||
@JSONField(ordinal = 1) | ||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
|
||
public int[] getLocation() { | ||
return location; | ||
} | ||
|
||
@JSONField(ordinal = 3) | ||
public void setLocation(int[] location) { | ||
this.location = location; | ||
} | ||
} | ||
} |