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
7 changed files
with
250 additions
and
6 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/test/java/com/alibaba/json/bvt/issue_1500/Issue1588.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,19 @@ | ||
package com.alibaba.json.bvt.issue_1500; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import junit.framework.TestCase; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class Issue1588 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
String dateString = "2017-11-17 00:00:00"; | ||
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateString); | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("test", date); | ||
System.out.println(jsonObject.toJSONString(jsonObject, SerializerFeature.UseISO8601DateFormat)); | ||
System.out.println(JSONObject.toJSONStringWithDateFormat(jsonObject, "yyyy-MM-dd'T'HH:mm:ssXXX")); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/java/com/alibaba/json/bvt/issue_1600/Issue1665.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,25 @@ | ||
package com.alibaba.json.bvt.issue_1600; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.TypeReference; | ||
import com.alibaba.fastjson.parser.ParserConfig; | ||
import com.alibaba.fastjson.util.TypeUtils; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.Collection; | ||
|
||
public class Issue1665 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
TypeReference<Collection<Model>> typeReference = new TypeReference<Collection<Model>>() {}; | ||
|
||
|
||
Collection<Model> collection = TypeUtils.cast(JSON.parse("[{\"id\":101}]"), typeReference.getType(), ParserConfig.getGlobalInstance()); | ||
assertEquals(1, collection.size()); | ||
Model model = collection.iterator().next(); | ||
assertEquals(101, model.id); | ||
} | ||
|
||
public static class Model { | ||
public int id; | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
src/test/java/com/alibaba/json/bvt/issue_1600/Issue_for_gaorui.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.issue_1600; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.parser.Feature; | ||
import junit.framework.TestCase; | ||
|
||
public class Issue_for_gaorui extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
String json = "{\"@type\":\"java.util.HashMap\",\"COUPON\":[{\"@type\":\"com.alibaba.json.bvt.issue_1600.Issue_for_gaorui.PromotionTermDetail\",\"activityId\":\"1584034\",\"choose\":true,\"couponId\":1251068987,\"couponType\":\"limitp\",\"match\":true,\"realPrice\":{\"amount\":0.6,\"currency\":\"USD\"}}],\"grayTrade\":\"true\"}"; | ||
|
||
JSON.parseObject(json, Object.class, Feature.SupportAutoType); | ||
} | ||
|
||
public static class PromotionTermDetail { | ||
/** | ||
* 卡券Id | ||
*/ | ||
private Long couponId; | ||
/** | ||
* 营销Id | ||
*/ | ||
private String promotionId; | ||
/** | ||
* 实际单价 | ||
*/ | ||
private Money realPrice; | ||
/** | ||
* 活动Id | ||
*/ | ||
private String activityId; | ||
|
||
/** | ||
* 卡券类型 | ||
*/ | ||
private String couponType; | ||
|
||
/** | ||
* 是否能够获取到该优惠 | ||
*/ | ||
private boolean isMatch = false; | ||
/** | ||
* 是否选择了该优惠 | ||
*/ | ||
private boolean isChoose = false; | ||
/** | ||
* 未获取到优惠的原因 | ||
*/ | ||
private String reasonForLose; | ||
/** | ||
* 未获取优惠的标识码 | ||
*/ | ||
private String codeForLose; | ||
|
||
public Long getCouponId() { | ||
return couponId; | ||
} | ||
|
||
public void setCouponId(Long couponId) { | ||
this.couponId = couponId; | ||
} | ||
|
||
public String getPromotionId() { | ||
return promotionId; | ||
} | ||
|
||
public void setPromotionId(String promotionId) { | ||
this.promotionId = promotionId; | ||
} | ||
|
||
public Money getRealPrice() { | ||
return realPrice; | ||
} | ||
|
||
public void setRealPrice(Money realPrice) { | ||
this.realPrice = realPrice; | ||
} | ||
|
||
public String getActivityId() { | ||
return activityId; | ||
} | ||
|
||
public void setActivityId(String activityId) { | ||
this.activityId = activityId; | ||
} | ||
|
||
public String getCouponType() { | ||
return couponType; | ||
} | ||
|
||
public void setCouponType(String couponType) { | ||
this.couponType = couponType; | ||
} | ||
|
||
public boolean isMatch() { | ||
return isMatch; | ||
} | ||
|
||
public void setMatch(boolean match) { | ||
isMatch = match; | ||
} | ||
|
||
public boolean isChoose() { | ||
return isChoose; | ||
} | ||
|
||
public void setChoose(boolean choose) { | ||
isChoose = choose; | ||
} | ||
|
||
public String getReasonForLose() { | ||
return reasonForLose; | ||
} | ||
|
||
public void setReasonForLose(String reasonForLose) { | ||
this.reasonForLose = reasonForLose; | ||
} | ||
|
||
public String getCodeForLose() { | ||
return codeForLose; | ||
} | ||
|
||
public void setCodeForLose(String codeForLose) { | ||
this.codeForLose = codeForLose; | ||
} | ||
} | ||
|
||
public static class Money { | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/java/com/alibaba/json/bvt/issue_1700/Issue1761.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,13 @@ | ||
package com.alibaba.json.bvt.issue_1700; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import junit.framework.TestCase; | ||
|
||
public class Issue1761 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("null",""); | ||
double d = jsonObject.getDoubleValue("null"); | ||
assertEquals(d, 0.0D); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
src/test/java/com/alibaba/json/bvt/parser/autoType/AutoTypeTest3_deny.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,54 @@ | ||
package com.alibaba.json.bvt.parser.autoType; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.parser.Feature; | ||
import junit.framework.TestCase; | ||
|
||
public class AutoTypeTest3_deny extends TestCase { | ||
public void test_for_x() throws Exception { | ||
Exception error = null; | ||
try { | ||
String json = "{\"@type\":\"java.util.logging.FileHandler\",\"pattern\":\"xxx.txt\"}"; | ||
Object obj = JSON.parse(json, Feature.SupportAutoType); | ||
} catch (Exception ex) { | ||
error = ex; | ||
} | ||
assertNotNull(error); | ||
} | ||
|
||
public void test_for_jar() throws Exception { | ||
Exception error = null; | ||
try { | ||
String json = "{\"@type\":\"java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}"; | ||
Object obj = JSON.parse(json, Feature.SupportAutoType); | ||
} catch (Exception ex) { | ||
error = ex; | ||
} | ||
assertNotNull(error); | ||
} | ||
|
||
public void test_for_array() throws Exception { | ||
Exception error = null; | ||
try { | ||
String json = "{\"@type\":\"[java.util.jar.JarFile.JarFile\",\"name\":\"xxx.txt\"}"; | ||
Object obj = JSON.parse(json, Feature.SupportAutoType); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
error = ex; | ||
} | ||
assertNotNull(error); | ||
} | ||
|
||
|
||
public void test_for_array_1() throws Exception { | ||
Exception error = null; | ||
try { | ||
String json = "{\"@type\":\"L[java.util.jar.JarFile.JarFile;\",\"name\":\"xxx.txt\"}"; | ||
Object obj = JSON.parse(json, Feature.SupportAutoType); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
error = ex; | ||
} | ||
assertNotNull(error); | ||
} | ||
} |
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