发送大型 pojo 时,我想检查字节变化而不是结构的细节差异。也许在内存中序列化和散列 pojo,但这在 Android 设备上可能会失败。任何想法都会令人兴奋。也许应该遍历它的dom样式。
出去
outputStreamWriter = new OutputStreamWriter( out, "UTF-8");
jsonWriter = new JsonWriter(outputStreamWriter);
jsonWriter.setIndent(" ");
jsonWriter.setIndent("\t");
jsonWriter. beginArray();
mygson.toJson( largeTestPojo, LargeTestPojo.class, jsonWriter );
jsonWriter.endArray();
jsonWriter.flush();
在
InputStreamReader isr = new InputStreamReader( in, "UTF-8");
StatsTypeAdapterFactory stats = new StatsTypeAdapterFactory();
Gson gson = new GsonBuilder().registerTypeAdapterFactory(stats).create();
jsonReader = new JsonReader( isr );
jsonReader. beginArray();
largeTestPojo= gson.fromJson( jsonReader, LargeTestPojo.class );
jsonReader.endArray();