Gson: fromJson() and toJson broken for Camera.Paramteres in Android 9 (android targetSdkVersion 28 and device os 9.0)

Created on 13 Nov 2018  Â·  1Comment  Â·  Source: google/gson

library : "com.google.code.gson:gson:2.8.5"
gradle : 'com.android.tools.build:gradle:3.2.1'

The problem occurs when the app is built with compileSdkVersion 28 and runs on an Android 9 device.

The Camera.Parameters object can't be serialized. An already seirialized instance of this object (created when the app was build with compileSdkVersion 27 and stored as a file) is deserialized into an Camera.Parameters object without the private fields set correctly.

Perhaps the problem is related to the behavioral changes of Android 9 mentioned here. In that case, is there a workaround?

Most helpful comment

You need to write your own type adapter using the public API. You should
never serialize the private members of types you don't control.

On Tue, Nov 13, 2018, 11:17 AM Petros Douvantzis <[email protected]
wrote:

library : "com.google.code.gson:gson:2.8.5"
gradle : 'com.android.tools.build:gradle:3.2.1'

The problem occurs when the app is built with compileSdkVersion 28 and
runs on an Android 9 device.

The Camera.Parameters
https://developer.android.com/reference/android/hardware/Camera.Parameters
object can't be serialized. An already seirialized instance of this object
(created when the app was build with compileSdkVersion 27 and stored as a
file) is deserialized into an Camera.Parameters object without the private
fields set correctly.

Perhaps the problem is related to the behavioral changes of Android 9
mentioned here
https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces.
In that case, is there a workaround?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/1427, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEdyCKHbgDt0ZxS2vYkMT_jyLCxlXks5uuvCrgaJpZM4Yb_-7
.

>All comments

You need to write your own type adapter using the public API. You should
never serialize the private members of types you don't control.

On Tue, Nov 13, 2018, 11:17 AM Petros Douvantzis <[email protected]
wrote:

library : "com.google.code.gson:gson:2.8.5"
gradle : 'com.android.tools.build:gradle:3.2.1'

The problem occurs when the app is built with compileSdkVersion 28 and
runs on an Android 9 device.

The Camera.Parameters
https://developer.android.com/reference/android/hardware/Camera.Parameters
object can't be serialized. An already seirialized instance of this object
(created when the app was build with compileSdkVersion 27 and stored as a
file) is deserialized into an Camera.Parameters object without the private
fields set correctly.

Perhaps the problem is related to the behavioral changes of Android 9
mentioned here
https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces.
In that case, is there a workaround?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/gson/issues/1427, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEdyCKHbgDt0ZxS2vYkMT_jyLCxlXks5uuvCrgaJpZM4Yb_-7
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GoogleCodeExporter picture GoogleCodeExporter  Â·  15Comments

GoogleCodeExporter picture GoogleCodeExporter  Â·  14Comments

GoogleCodeExporter picture GoogleCodeExporter  Â·  25Comments

GoogleCodeExporter picture GoogleCodeExporter  Â·  16Comments

JakeWharton picture JakeWharton  Â·  39Comments