-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Android M: Cannot make field constructor accessible #648
Comments
Maybe relevant: http://developer.android.com/preview/behavior-changes.html#behavior-art-runtime Not exactly the cause here, but not surprising that since it's in the same vein it might have been effected. |
@JakeWharton I tried simulate this error without success. |
Are we trying to deserialize an instance of
|
Seems a reasonable guess. This isn't my original bug, I was just moving it from a project I work on. |
I get this with an app on a Nexus 6 running Android M. |
just updated the Nexus 5 to the latest Android M preview and getting the same error. As it was working before, it seems to be only a problem with the most recent version of Android M (Build MPA44I)? |
Hopefully Google will fix it before releasing Android M. Gson is used in a fairly large number of Android projects, and breaking them will be a big no no. |
@cdreier are you using Gson on an instance of java.lang.reflect.Field? That's superweird. The right fix for this is to write a type adapter for that class. |
@swankjesse no, i'm using Retrofit for a few rest-calls. I think i figured out a bit more, perhaps something changed in the List interface? Simple Retrofit service: public interface SynchronisationService {
@GET("/rooms/all")
public void getAll(Callback<List<Room>> rooms);
}
public class Room {
private String name;
private int id;
private List<LightSwitch> switches;
/** ... **/
} Response is something like this: [
{
"name": "livingroom",
"id": "1",
"switches": [
{
"name": "big lamp",
"id": "1"
},
{
"name": "smaller lamp",
"id": "2"
}
]
}
] Without this switch-list in my room, everything is working fine! |
You can try adding GsonConverter new GsonConverter(new GsonBuilder()
.excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC)
.serializeNulls()
.create()) In your RestAdapter.Builder() RestAdapter.Builder()
.setConverter(new GsonConverter(new GsonBuilder()
.excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC)
.serializeNulls()
.create()))
.setEndpoint(endPoint)
.build() |
I am using Retrofit and GSON in a project and only encountered this issue on Android M after replacing SugarORM with ActiveAndroid. |
Is there any progress with this one? It is present with the official Android 6 release. |
We experienced this same issue on our app on official Android 6 release. Adding this to our GsonBuilder as seen above seemed to resolve the issue. new GsonBuilder()
.excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC) |
perhaps something changed with the reflection api in android 6? public class Switch {
public String name;
public Room room;
public int id;
private transient SwitchService switchService;
} |
yeah @crowdcast-hk already resolve this issue. its work. |
It seams bug has been fixed in new version (2.4) . |
upgraded to 2.4 but app still crashes with the same exception on Marshmallow |
Did you try to exclude fields with modifiers? |
@inisic if you need to add these lines, problem is not fixed :) In my case, I don't use gson with retrofit (only gson) but i have the same problem. .excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC) problem is still here. To solve my problem, i have to set excludeFieldsWithoutExposeAnnotation() But i have to expose all fields i need ><. Is there a way to know where is the problem ? In the stacktrace, there is no reference to my code |
This exclude(excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC) didn't help me. Class which extends Object is deserialized correctly, but classes which extends Model from ActiveAndroid throws exception. I found only one solution => write custom deserializer. I hope this is only temporary solution and this will be fix at GSON library. |
The cause continues to seem like the use of Class or Field in the On Tue, Oct 27, 2015, 9:02 PM DavidKrybus notifications@github.com wrote:
|
I'm in the same boat. My tests pass running in API 22, but fail for API 23. |
I had the same issue. I'm using Gson with Retrofit and ActiveAndroid. The solution with
suggested by @aat-antoine works for me. |
Im using Retrofit + Gson so I used the excludeFIeldsWithouAnnotation() option and it worked.
|
@jirivrany Thanks |
I'm having this issue on Android M as well. Any idea what |
You’re using |
@swankjesse That's an log error I'm getting (along with everyone else using Anyone using ActiveAndroid having problems using the |
@aeroechelon I was trying to use ActiveAndroid and Gson and my workaround is fine for parsing the data with gson, but when I try to save fields that have relationships it doesnt work. |
I use Gson's ExclusionStrategy to skip
|
I had the same problem when using Retrofit + Gson + ActiveAndroid, but when i insert this line excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC)" in my GsonBuilder() it worked, but I do not understand what happened :( |
👍 to |
@jirivrany |
i tried this like Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC) retrofit = new Retrofit.Builder() but still getting same error. i am using retrofit + GSON+ Active Android. |
I'm using OkHttp + Gson + ActiveAndroid
work for me |
This continues to look like the serialization of |
I'm using Retrofit+ Gson + ActiveAndroid GsonBuilder builder = new GsonBuilder(); worked for me |
…nd above. Th issue was related to the GSON library as discussed under - google/gson#648
Mmm. Did you using extension of Kotlin language? I've writen function exension for base model:
fun Model.toJson(): String {
return try {
Gson().toJson(this@toJson, Model::class.java)
} catch(exception: Exception) {
"{}"
}
} I move it into |
This worked for me, thanks @zhenglingxiao |
Originally filed at square/retrofit#870.
Note: this might be a bug in the preview OS runtime and not Gson, but it's definitely not a Retrofit problem.
The text was updated successfully, but these errors were encountered: