2014-10-08 17 views
15

Realm + GSON'u kullanmaya çalışıyorum. Eğer birlikte iyi çalışırlarsa, cennette yapılan bir eşleşme olurdu. Tüm müsait düzeltmekGSON & Realm oyunlarını güzel yapmak

10-08 17:00:19.578 12492-12492/appwise.be.gsontestproject E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: appwise.be.gsontestproject, PID: 12492 
    java.lang.StackOverflowError 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:372) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:381) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376) 
      at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:356) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:128) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:75) 
      at com.google.gson.Gson.getAdapter(Gson.java:358) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:109) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:46) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:84) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:83) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:129) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:75) 
      at com.google.gson.Gson.getAdapter(Gson.java:358) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:109) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.access$100(ReflectiveTypeAdapterFactory.java:46) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:84) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:83) 
      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:129) 
      at com.google.gson.internal.bin 

: Ben ile benim modeli nesneleri uzatmak zaman

Ancak, "RealmObject uzanır" Ben bu olsun? :-)

+2

GSON bir hata olduğu anlaşılıyor. Ayrıca bkz: http://stackoverflow.com/questions/14565647/gson-2-2-2-causing-a-stackoverflow-on-4-2-1-only?rq=1. Aynı sorunu yaşadık. – bmunk

+0

1.7.1 için indirme hilesi işe yarıyor! – TomCB

cevap

26

U böyle yapabilirsiniz:

Gson gson = new GsonBuilder() 
    .setExclusionStrategies(new ExclusionStrategy() { 
     @Override 
     public boolean shouldSkipField(FieldAttributes f) { 
      return f.getDeclaringClass().equals(RealmObject.class); 
     } 

     @Override 
     public boolean shouldSkipClass(Class<?> clazz) { 
      return false; 
     } 
    }) 
    .create(); 

String json = "{ name : 'John', email : '[email protected]' }"; User user = gson.fromJson(json, User.class);

http://realm.io/docs/java/0.77.0/#gson

+0

<3 kesinlikle mükemmel – Broak

+0

@KillNono, Bana çok zaman kazandırdı. Teşekkürler!! –

+1

Harika cevap, teşekkürler – dowjones123