Replace exist field from json that not content this field?
See original GitHub issuePOJO:
public class Offer extends RealmObject {
@PrimaryKey
private int id;
private String name;
private boolean downloaded;
}
I update field “download” by true like this (click special button in my app):
public static void update(final int offerId, final boolean downloaded) {
Realm realm = Realm.getDefaultInstance();
try {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Offer offer = realm.where(Offer.class).equalTo(Offer.ID, offerId).findFirst();
offer.setDownloaded(downloaded);
}
});
} finally {
realm.close();
}
}
OK. It’s work. Now field download = true. And I need this field not change any more!
But then incoming json like this (in this json no field “download”)
[
{
"id": 1,
"name": "my name"
},
{
"id": 2,
"name": "my name2"
}
]
I update Offer like this :
public static void updateOffers(final List<Offer> offersList) {
Realm realm = Realm.getDefaultInstance();
try {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
RealmList<Offer> offersRealmList = new RealmList<>();
offersRealmList.addAll(offersList);
realm.copyToRealmOrUpdate(offersRealmList);
}
});
} finally {
realm.close();
}
}
And after this update all fields “download” again = FALSE!!!
Questions: 1.This is a normal of Realm to replace exist field? (In json no this field) 2.How avoid to replace filed “download”?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Removing a field from jSon String - Stack Overflow
This above object is a dynamic object returned as string I want to remove Violation related fields and its values from it. I...
Read more >Replace op should error out if path doesn't exist #119 - GitHub
Hi, As per Json RFC, path must exist for the operation to be successful. ... of this repository and replace does indeed fail...
Read more >Modifying JSON data using JSON_MODIFY() in SQL Server
Suppose we specify a property in the path argument that does not exist, in this case, the JSON_MODIFY function tries to insert the...
Read more >Working with Json fields (Concepts) - Prisma
You need to store data that does not have a consistent structure ... JsonObject utility classes to work with the contents of a...
Read more >Validate, Query, and Change JSON Data with Built-in Functions
Validate JSON text by using the ISJSON function. The ISJSON function tests whether a string contains valid JSON. The following example returns ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

yes, that would be a fine solution for now.
We have an issue to track this #2288
Note: When client click button(download) field
Offer.download = trueand MUST never change!So as result here my solution:
Get all offers with download = true;
Algorithm:
offersDownloadTrueListnewStoresListnewStoresList- create from incoming Json (without field “download”)Here implementation:
And now in Realm offers that has field download = true not change. OK. It’s work. Fine.
The question is: Is this a best solution?