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.
bug fixed for BeanToArray with PropertyFilters. for issue #1580
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
src/test/java/com/alibaba/json/bvt/issue_1500/Issue1580.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,42 @@ | ||
package com.alibaba.json.bvt.issue_1500; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.SerializeFilter; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter; | ||
import junit.framework.TestCase; | ||
|
||
public class Issue1580 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
SimplePropertyPreFilter classAFilter = new SimplePropertyPreFilter(Model.class, "code"); | ||
SerializeFilter[] filters =new SerializeFilter[]{classAFilter}; | ||
|
||
Model model = new Model(); | ||
model.code = 1001; | ||
model.name = "N1"; | ||
|
||
String json = JSON.toJSONString(model, filters, SerializerFeature.BeanToArray ); | ||
assertEquals("[1001,null]", json); | ||
} | ||
|
||
public static class Model { | ||
private int code; | ||
private String name; | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(int code) { | ||
this.code = code; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
} |