-1

Following is Pojo are extended by realm , at first time getting all fields from api and i am using insertOrUpdate() operation of realm to dump data in realm.

ServiceModel.java

@JsonProperty("id")
private String id;

@JsonProperty("title")
private String title;

@JsonProperty("description")
private String description;

@JsonProperty("current_status")
private String currentStatus;

But for next time i am not getting current_status field from response and so my ServiceModel table is getting updated with currentStatus as null. How To make currentStatus to not getting updated if it is not in response.

Harshad07
  • 608
  • 7
  • 23
  • If you import the data as pure JSON, it will correctly ignore missing fields. In the case where you convert to an object first because the JSON names doesn't match what you use in Java, it, unfortunately, gets a little more tricky and you probably need to do it by hand. – Christian Melchior Jan 26 '18 at 18:36

1 Answers1

1

I had the same problem and here how I solved it. You should select existing Object by id:

ServiceModel existingService = realm.where(ServiceModel.class).equalsTo("id",id).findFirst();

if(existingService !=null){ // check if such record existed, it may be absent
    String oldCurrentStatus = existingService.currentStatus();
    //set old current status to new API object
}

I had the same problem and as far as I know there is no Realm function or annotation yet for such case.

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82