How get list of inner POJOs more simple?
See original GitHub issueRealm 4.1.
My POJOs:
public class Store extends RealmObject {
@PrimaryKey
private int id;
private RealmList<Product> products = new RealmList<>();
}
public class Product extends RealmObject {
@PrimaryKey
private int id;
private String name;
}
I want to get list of all products of all stores.
Here my code.
public static List<Product> getProductsList() {
Realm realm = Realm.getDefaultInstance();
try {
List<Product> allProductsList = new ArrayList<>();
RealmResults<Store> realmResultsStores = realm.where(Store.class).findAll();
for (Store store : realmResultsStores) {
RealmList<Product> merachantProductsList = store.getProducts();
allProductsList.addAll(realm.copyFromRealm(merachantProductsList));
}
return allProductsList;
} finally {
realm.close();
}
}
It’s work. Fine. But I think it’s to much code. The question is: Is there an easier way to get list of all products of all stores?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Stream of a nested POJOs List to a another POJO LIST
You will first need a flatMap to create a stream of all InvoiceDetails in ... You can easily make a List from a...
Read more >07 - Create Complex Nested Post Request body Using POJO ...
Here is the link of Full Play List ▻ https://bit.ly/2BY0vHuHere you will learn how to create a Complicated Post Request body on Runtime ......
Read more >How to convert Nested JSON object to the Java ... - YouTube
In this video you will learn how to convert nested json object to the java pojo in easy way.Click here for More ......
Read more >Nested pojo java class - What could I make better
Consider using constructors which set all fields (Lombok's @AllArgsConstructor ) which can make building the classes easier instead if ...
Read more >Mapping Nested Values with Jackson - Baeldung
Learn three ways to deserialize nested JSON values in Java using the Jackson library.
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

I recommend
Yes, in my fragment I use
private RealmResults<Product> productRealmResults;I use this to can add listener to Realm. And I use
RealmRecyclerViewAdapterSo I return to fragment exact
RealmResults<Product>.OK. Thanks