Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved gzip bytes support, fix #3614
- Loading branch information
Showing
2 changed files
with
53 additions
and
6 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
32 changes: 32 additions & 0 deletions
32
src/test/java/com/alibaba/json/bvt/issue_3600/Issue3614.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,32 @@ | ||
package com.alibaba.json.bvt.issue_3600; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.JSONObject; | ||
import junit.framework.TestCase; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.*; | ||
import java.util.Collections; | ||
import java.util.zip.GZIPOutputStream; | ||
|
||
public class Issue3614 extends TestCase { | ||
public void test_for_issue() throws Exception { | ||
byte[] gzipBytes = gzip(JSON.toJSONString(Collections.singletonMap("key", "value")).getBytes()); | ||
|
||
Object o = JSON.parseObject(gzipBytes, JSONObject.class); | ||
assertEquals("{\"key\":\"value\"}", JSON.toJSONString(o)); | ||
} | ||
|
||
private static byte[] gzip(byte[] source) throws IOException { | ||
if (source == null) return null; | ||
|
||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
GZIPOutputStream gzip = new GZIPOutputStream(bos); | ||
gzip.write(source); | ||
gzip.finish(); | ||
byte[] bytes = bos.toByteArray(); | ||
gzip.close(); | ||
return bytes; | ||
} | ||
|
||
} |