bluelinelabs / LoganSquare

Screaming fast JSON parsing and serialization library for Android.
Apache License 2.0
3.21k stars 306 forks source link

Update existing object with json data #157

Open krzysztof-miemiec opened 8 years ago

krzysztof-miemiec commented 8 years ago

Currently there is no way to insert json data to an object that already exists.

It would be great to be able to do as below (use case for Realm):

@JsonObject
public class MyObject extends RealmObject {
  @JsonField
  @JsonObjectId
  String id;

  @JsonField
  int someField;

  @JsonField
  String anotherField;

  @OnJsonIdRead
  MyObject onJsonIdRead(String id){
    return MyRealmManager.getRealm().where(MyObject.class).equalTo("id", id).findFirst();
  }
}

It would solve a problem with server returning different versions of json i.e. we already have id and anotherField, but in some call server returns only id and someField. Realm can't help with it's createOrUpdateAllFromJson().

krzysztof-miemiec commented 8 years ago

See https://github.com/rs411/LoganSquare for implementation.