@@ -91,6 +91,7 @@ public static CodegenResult genArray(String cacheKey, ClassInfo classInfo) {
9191 }
9292
9393 private static CodegenResult genList (String cacheKey , Class clazz , Type compType ) {
94+ boolean noIndention = JsoniterSpi .getCurrentConfig ().indentionStep () == 0 ;
9495 boolean isCollectionValueNullable = true ;
9596 if (cacheKey .endsWith ("__value_not_nullable" )) {
9697 isCollectionValueNullable = false ;
@@ -99,8 +100,13 @@ private static CodegenResult genList(String cacheKey, Class clazz, Type compType
99100 ctx .append ("public static void encode_(java.lang.Object obj, com.jsoniter.output.JsonStream stream) throws java.io.IOException {" );
100101 ctx .append ("java.util.List list = (java.util.List)obj;" );
101102 ctx .append ("int size = list.size();" );
102- ctx .append ("if (size == 0) { return; }" );
103- ctx .buffer ('[' );
103+ if (noIndention ) {
104+ ctx .append ("if (size == 0) { return; }" );
105+ ctx .buffer ('[' );
106+ } else {
107+ ctx .append ("if (size == 0) { stream.write((byte)'[', (byte)']'); return; }" );
108+ ctx .append ("stream.writeArrayStart(); stream.writeIndention();" );
109+ }
104110 ctx .append ("java.lang.Object e = list.get(0);" );
105111 if (isCollectionValueNullable ) {
106112 ctx .append ("if (e == null) { stream.writeNull(); } else {" );
@@ -110,7 +116,11 @@ private static CodegenResult genList(String cacheKey, Class clazz, Type compType
110116 CodegenImplNative .genWriteOp (ctx , "e" , compType , false );
111117 }
112118 ctx .append ("for (int i = 1; i < size; i++) {" );
113- ctx .append ("stream.write(',');" );
119+ if (noIndention ) {
120+ ctx .append ("stream.write(',');" );
121+ } else {
122+ ctx .append ("stream.writeMore();" );
123+ }
114124 ctx .append ("e = list.get(i);" );
115125 if (isCollectionValueNullable ) {
116126 ctx .append ("if (e == null) { stream.writeNull(); } else {" );
@@ -120,7 +130,11 @@ private static CodegenResult genList(String cacheKey, Class clazz, Type compType
120130 CodegenImplNative .genWriteOp (ctx , "e" , compType , false );
121131 }
122132 ctx .append ("}" ); // for
123- ctx .buffer (']' );
133+ if (noIndention ) {
134+ ctx .buffer (']' );
135+ } else {
136+ ctx .append ("stream.writeArrayEnd();" );
137+ }
124138 ctx .append ("}" ); // public static void encode_
125139 return ctx ;
126140 }
0 commit comments