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
5 changed files
with
170 additions
and
10 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
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
65 changes: 65 additions & 0 deletions
65
src/test/java/com/alibaba/json/bvt/issue_1600/Issue1635.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,65 @@ | ||
package com.alibaba.json.bvt.issue_1600; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.NameFilter; | ||
import com.alibaba.fastjson.serializer.SerializeConfig; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.List; | ||
|
||
public class Issue1635 extends TestCase { | ||
public static class Foo { | ||
public String name; | ||
public Integer BarCount; | ||
public Boolean flag; | ||
public List list; | ||
|
||
public Foo(String name, Integer barCount) { | ||
this.name = name; | ||
BarCount = barCount; | ||
} | ||
} | ||
|
||
public void test_issue() throws Exception { | ||
SerializeConfig config = new SerializeConfig(); | ||
Foo foo = new Foo(null, null); | ||
String json = JSON.toJSONString(foo | ||
, config, new PascalNameFilter() | ||
, SerializerFeature.WriteNullBooleanAsFalse | ||
, SerializerFeature.WriteNullNumberAsZero | ||
, SerializerFeature.WriteNullStringAsEmpty | ||
, SerializerFeature.WriteNullListAsEmpty | ||
); | ||
assertEquals("{\"BarCount\":0,\"Flag\":false,\"List\":[],\"Name\":\"\"}", json); | ||
} | ||
|
||
public void test_issue_1() throws Exception { | ||
SerializeConfig config = new SerializeConfig(); | ||
Foo foo = new Foo(null, null); | ||
String json = JSON.toJSONString(foo | ||
, config, new PascalNameFilter() | ||
, SerializerFeature.WriteNullBooleanAsFalse | ||
, SerializerFeature.WriteNullNumberAsZero | ||
, SerializerFeature.WriteNullStringAsEmpty | ||
, SerializerFeature.WriteNullListAsEmpty | ||
, SerializerFeature.BeanToArray | ||
); | ||
assertEquals("[0,false,[],\"\"]", json); | ||
} | ||
|
||
public class PascalNameFilter implements NameFilter { | ||
|
||
public String process(Object source, String name, Object value) { | ||
if (name == null || name.length() == 0) { | ||
return name; | ||
} | ||
|
||
char[] chars = name.toCharArray(); | ||
chars[0]= Character.toUpperCase(chars[0]); | ||
|
||
String pascalName = new String(chars); | ||
return pascalName; | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/com/alibaba/json/bvt/issue_1600/Issue1647.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,50 @@ | ||
package com.alibaba.json.bvt.issue_1600; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.PropertyNamingStrategy; | ||
import com.alibaba.fastjson.annotation.JSONType; | ||
import junit.framework.TestCase; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class Issue1647 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
Params params = new Params() | ||
.setVerificationIds(Arrays.asList(new String[]{"a", "b"})) | ||
.setWithFields(true); | ||
|
||
String json = JSON.toJSONString(params); | ||
System.out.println(json); | ||
params = JSON.parseObject(json, Params.class); | ||
assertEquals("{\"verification_ids\":[\"a\",\"b\"],\"with_fields\":true}", JSON.toJSONString(params)); | ||
} | ||
|
||
@JSONType(naming = PropertyNamingStrategy.SnakeCase) | ||
public static class Params { | ||
|
||
private boolean withFields; | ||
|
||
private List<String> verificationIds; | ||
|
||
public boolean isWithFields() { | ||
return withFields; | ||
} | ||
|
||
public Params setWithFields(boolean withFields) { | ||
this.withFields = withFields; | ||
return this; | ||
} | ||
|
||
public List<String> getVerificationIds() { | ||
return verificationIds; | ||
} | ||
|
||
public Params setVerificationIds(List<String> verificationIds) { | ||
this.verificationIds = verificationIds; | ||
return this; | ||
} | ||
} | ||
|
||
|
||
} |