package com.alibaba.json;

import com.alibaba.fastjson.JSONWriter;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;

class CertFile {
    public String name;
    public byte[] data;
}

public class ByteArrayTest {

    public static void main(String[] args) {
        try {
            CertFile file = new CertFile();
            file.name = "testname";

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 2048; i++) {
                sb.append("1");
            }
            file.data = sb.toString().getBytes();

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            JSONWriter writer = new JSONWriter(new OutputStreamWriter(bos));
            writer.config(SerializerFeature.WriteClassName, true);
            writer.writeObject(file);
            writer.flush();

            System.out.println(bos);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

@@ -52,22 +52,149 @@
 son.JSON
-Writer
+;%0Aimport com.alibaba.fastjson.JSONWriter;%0Aimport com.alibaba.fastjson.parser.Feature;%0Aimport com.alibaba.fastjson.parser.ParserConfig
 ;%0Aimport
@@ -246,16 +246,65 @@
 ature;%0A%0A
+import org.junit.Assert;%0Aimport org.junit.Test;%0A%0A
 import j
@@ -368,17 +368,100 @@
 Writer;%0A
-%0A
+import java.nio.charset.Charset;%0A%0A%0Apublic class ByteArrayTest  %7B%0A%0A    public static 
 class Ce
@@ -469,16 +469,20 @@
 tFile %7B%0A
+    
     publ
@@ -497,24 +497,28 @@
 g name;%0A    
+   
+ 
 public byte%5B
@@ -529,40 +529,24 @@
 ta;%0A
-%7D%0A%0Apublic class ByteArray
+    %7D%0A%0A    @
 Test
- %7B%0A
 %0A   
@@ -557,60 +557,109 @@
 lic 
-static void main(String%5B%5D args) %7B%0A        try %7B%0A    
+void test_0() throws Exception %7B%0A        ParserConfig.getGlobalInstance().setAutoTypeSupport(true);%0A%0A
     
@@ -698,28 +698,24 @@
 ();%0A        
-    
 file.name = 
@@ -735,20 +735,16 @@
         
- 
-   
 StringBu
@@ -783,20 +783,16 @@
         
-   
- 
 for (int
@@ -828,20 +828,16 @@
         
-    
 sb.appen
@@ -856,24 +856,18 @@
     
-    %7D%0A  
+%7D%0A
         
   fi
@@ -858,26 +858,24 @@
   %7D%0A        
-  
 file.data = 
@@ -897,28 +897,24 @@
 etBytes();%0A%0A
-    
         Byte
@@ -974,20 +974,16 @@
         
-    
 JSONWrit
@@ -1043,28 +1043,24 @@
 ));%0A        
- 
-   
 writer.confi
@@ -1106,28 +1106,24 @@
 e);%0A        
-    
 writer.write
@@ -1132,28 +1132,24 @@
 ject(file);%0A
-    
         writ
@@ -1169,20 +1169,16 @@
         
-    
 System.o
@@ -1194,24 +1194,25 @@
 n(bos);%0A
+%0A
         
 %7D catch 
@@ -1207,76 +1207,490 @@
     
-%7D catch (Exception ex) %7B%0A            ex.printStackTrace();%0A        %7D
+byte%5B%5D data = bos.toByteArray();%0A        Charset charset = Charset.forName(%22UTF-8%22);%0A        CertFile convertFile =  (CertFile)JSON.parse(data, 0, data.length, charset.newDecoder(), Feature.AllowArbitraryCommas,%0A                Feature.IgnoreNotMatch, Feature.SortFeidFastMatch, Feature.DisableCircularReferenceDetect,%0A                Feature.AutoCloseSource);%0A%0A        Assert.assertEquals(file.name, convertFile.name);%0A        Assert.assertArrayEquals(file.data, convertFile.data);
 %0A   

use junit testcase