Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
add more toJSONBytes method. for issue #1628
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Dec 8, 2017
1 parent 9a1f9c0 commit f1cd9f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/com/alibaba/fastjson/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,11 @@ public static byte[] toJSONBytes(Object object, SerializeConfig config, int defa
* @since 1.2.42
*/
public static byte[] toJSONBytes(Object object, SerializeFilter[] filters, SerializerFeature... features) {
return toJSONBytes(object, SerializeConfig.globalInstance, emptyFilters, DEFAULT_GENERATE_FEATURE, features);
return toJSONBytes(object, SerializeConfig.globalInstance, filters, DEFAULT_GENERATE_FEATURE, features);
}

public static byte[] toJSONBytes(Object object, SerializeConfig config, SerializeFilter filter, SerializerFeature... features) {
return toJSONBytes(object, config, new SerializeFilter[] {filter}, DEFAULT_GENERATE_FEATURE, features);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/alibaba/json/bvt/issue_1600/Issue1628.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.alibaba.json.bvt.issue_1600;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import junit.framework.TestCase;

Expand All @@ -15,4 +17,20 @@ public void test_toJSONBytes() throws Exception {
byte[] bytes = JSON.toJSONBytes(map, new SimplePropertyPreFilter("a"));
assertEquals("{\"a\":1001}", new String(bytes));
}

public void test_toJSONBytes_1() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("a", 1001);
map.put("b", 2002);
byte[] bytes = JSON.toJSONBytes(map, new SerializeFilter[] {new SimplePropertyPreFilter("a")});
assertEquals("{\"a\":1001}", new String(bytes));
}

public void test_toJSONBytes_2() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("a", 1001);
map.put("b", 2002);
byte[] bytes = JSON.toJSONBytes(map, SerializeConfig.globalInstance, new SimplePropertyPreFilter("a"));
assertEquals("{\"a\":1001}", new String(bytes));
}
}

0 comments on commit f1cd9f9

Please sign in to comment.