Repository navigation
Closed
Description
Im using retrofit + gson to pull and parse some json from a webservice to this object. Now i want to use that same object as Model but i keep getting stackoverflow.
Is there anyway to fix this?
java.lang.StackOverflowError
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:380)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:375)
at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:355)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:117)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
at com.google.gson.Gson.getAdapter(Gson.java:356)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(ReflectiveTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
Here is my model:
@Table
public class Category extends BaseModel implements Parcelable {
public Category() {
super();
}
@Column(columnType = Column.PRIMARY_KEY)
@SerializedName("id")
public int mId;
@Column
@SerializedName("pantone")
public String mColor;
@SerializedName("langs")
public ArrayList mCategoryLanguageArrayList;
...
Metadata
Metadata
Assignees
Labels
No labels
Activity
agrosner commentedon Mar 4, 2015
This appears to be a GSON issue, not a DBFlow issue.
rhespanhol commentedon Mar 4, 2015
Thanks for your quick answer.
But you know any workaround to fix this?
agrosner commentedon Mar 4, 2015
looks good to me. I would debug GSON, and there is not much more I can do to help. Not that I don't want to, just I am not familiar with the library and not sure this error is a DBFlow issue.
intrications commentedon Mar 4, 2015
@rhespanhol
I solved this by using Gson's @expose annotation.
Pass a custom Gson to Retrofit:
Then add the @expose annotation to all your fields (that you want to deserialize) in your Model class.
Not sure why it works but it did.
rhespanhol commentedon Mar 5, 2015
Thanks @intrications, it worked!!
intrications commentedon Mar 6, 2015
What is ContainerAdapter? I didn't use that.
On 6 Mar 2015 18:11, "nambv" notifications@github.com wrote:
agrosner commentedon Mar 6, 2015
@nambv @intrications
@ContainerAdapteris used to generate an adapter to work withModelContainers. Rather than always generating it, I made it separated to cut down on generated code.rjam commentedon Mar 17, 2015
Instead of force exposing all fields, you should get the same result just by letting Gson know that it should not try to serialize/deserialize the contents of the
BaseModelclass your models are extending (namely theModelAdapterfield it holds). Try creating your gson instance like this and you should no longer need to add the@Exposeannotation to all fields:Rainer-Lang commentedon Mar 17, 2015
@rjam Many MANY THANKS!
intrications commentedon Mar 17, 2015
@rjam Thanks for that. I wasn't sure exactly what it was in
BaseModelthat was causing the problem.shashi2459 commentedon Jun 5, 2015
thanks guy`s....it was helpful.
AdamMTGreenberg commentedon Jun 28, 2015
This is also going to be an issue for anyone using Jackson + Retrofit + DBFlow.
The solution is for any class that
extends BaseModelmake sure you do something along the lines of:
anelrh26 commentedon Mar 1, 2016
I'm using retrofit + jackson. And I also want to use the same model for the DB and Jackson. But, I'm getting this error. Can someone help me? I don't know where is the error exactly
03-01 20:38:11.462 27759-27759/com E/art: Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 0 free bytes and 0B until OOM" (recursive case)
03-01 20:38:11.467 27759-27759/com E/art: "main" prio=5 tid=1 Runnable
03-01 20:38:11.467 27759-27759/com E/art: | group="main" sCount=0 dsCount=0 obj=0x73c14540 self=0xb4606800
03-01 20:38:11.467 27759-27759/com E/art: | sysTid=27759 nice=0 cgrp=apps sched=0/0 handle=0xb77b9160
03-01 20:38:11.467 27759-27759/com E/art: | state=R schedstat=( 924735144 476697697 652 ) utm=81 stm=10 core=0 HZ=100
03-01 20:38:11.467 27759-27759/com E/art: | stack=0xbf5a9000-0xbf5ab000 stackSize=8MB
03-01 20:38:11.467 27759-27759/com E/art: | held mutexes= "mutator lock"(shared held)
anelrh26 commentedon Mar 1, 2016
Forget it!
@AdamMTGreenberg is right!.
I just have to add the following in my model.