fairyhawk / protostuff

Automatically exported from code.google.com/p/protostuff
Apache License 2.0
0 stars 0 forks source link

Serialization\Deserialization of primitive & wrapper lists and arrays in JSonIOUtil #145

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1) Serialization gives the length of the list\array

        Schema schema = RuntimeSchema.getSchema(Integer.class);
        byte[] bytes = JsonIOUtil.toByteArray(listTets, schema, false);
        System.out.println(new String(bytes));

        Integer[] intArr = new Integer[]{1,2,3};
        byte[] byteArr = JsonIOUtil.toByteArray(intArr, schema, false);
        System.out.println("Int array  response " + new String(byteArr));

        List<Integer> intList = new ArrayList<Integer>();
        intList.add(1);
        intList.add(2);
        intList.add(3);
        byteArr = JsonIOUtil.toByteArray(intArr, schema, false);
        System.out.println("Int list response " + new String(byteArr));

2) Deserialization fails - I have used parseListFrom as the example which fails 
for primitive & primitive wrapper arrays and lists, what should be the ideal 
operation for array tupes serialization (The example is for a String list 
parsing?

Schema schema1 = RuntimeSchema.getSchema(String.class);
String jsonString = "[\"String1\",\"String2\"]";
StringReader reader = new StringReader(jsonString);
List<String> responseList = JsonIOUtil.parseListFrom(reader, schema1, false);

com.dyuproject.protostuff.JsonInputException: Expected token: { but was 
VALUE_STRING on message java.lang.String

What version of the product are you using? On what operating system?

1.0.7 on Win 7 enterprise.

Please provide any additional information below.

Original issue reported on code.google.com by vimalath...@gmail.com on 11 Jul 2013 at 5:59

GoogleCodeExporter commented 8 years ago
Like protobuf, the top level objects that you can directly serialize are 
limited to messages (pojos).
You cannot directly serialize primitive fields.

Use this instead:
message IntList {
  repeated int32 x = 1;
}

Original comment by david.yu...@gmail.com on 12 Jul 2013 at 1:04