-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json-io not working on Android 10 #141
Comments
Yes this is a big problem. Oddly, some auto-boxed primitives work (like Run this on an Android 10 or 11 device: // ArrayList<Long> works fine for serialization
ArrayList<Long> arrayList = new ArrayList<>(Arrays.asList(10L, 20L, 30L, 40L));
String serializedArrayList = JsonWriter.objectToJson(arrayList);
System.out.println("serializedArrayList = " + serializedArrayList); // prints {"@type":"java.util.ArrayList","@items":[10,20,30,40]}
// ArrayList<Integer> serializes to an empty array
ArrayList<Integer> arrayListInts = new ArrayList<>(Arrays.asList(10, 20));
serializedArrayList = JsonWriter.objectToJson(arrayListInts);
System.out.println("serializedArrayList = " + serializedArrayList); // prints {"@type":"java.util.ArrayList","@items":[{"@type":"int"},{"@type":"int"}]} Android Studio 4 (which uses Java 11) now shows a warning when running a pure unit test that uses json-io library:
I believe the same problem was reported here: #143 As an unrelated point, I noticed that the JsonWriter constructor has duplicate lines to read the property public JsonWriter(OutputStream out, Map<String, Object> optionalArgs)
{
...
writeLongsAsStrings = isTrue(args.get(WRITE_LONGS_AS_STRINGS));
writeLongsAsStrings = isTrue(args.get(WRITE_LONGS_AS_STRINGS));
...
} |
Regarding to Android docs (https://developer.android.com/about/versions/10/non-sdk-q) now value fields removed so reflection based mapping for primitives not working.
Ljava/lang/Boolean;->value:Z # java.lang.Boolean.booleanValue()
Ljava/lang/Byte;->value:B # java.lang.Byte.byteValue()
Ljava/lang/Character;->value:C # java.lang.Character.charValue()
Ljava/lang/Double;->value:D # java.lang.Double.doubleValue()
Ljava/lang/Float;->value:F # java.lang.Float.floatValue()
Ljava/lang/Integer;->value:I # java.lang.Integer.intValue()
Ljava/lang/Long;->value:J # java.lang.Long.longValue()
Ljava/lang/Short;->value:S # java.lang.Short.shortValue()
Workoround: can provide custom serializer for primitive types.
The text was updated successfully, but these errors were encountered: