I'm using RxJava2CrudRepository
to retrieve records from a table using findAll
method.
findAll return a Flowable<T> findAll();
Here is what I got.
@Override
public Flowable<Response> findByField(
String contract, String code) {
Supplier<Flowable<Response>> response=
() -> productRepository.findAll()
.toList()
.toFlowable();
//Some more logic to return final object
}
At this point everything works fine and I get the records from the database.
I need to iterate response
to do some logic with the data. When I run over using forEach I get the values from every record. ie:
response.get().forEach(m -> {
System.out.println("Value: " + m.getProductCode());
});
Output:
value: VAL1
value: VAL2
value: VAL3
...
But when I try to assing these values to a java bean the output is always null
Set<Response> headerReponse = new HashSet<>();
response.get().forEach(m -> {
Response response = new Response();
response.setServiceCode(m.getServiceCode());
response.setLegalDocumentNumber(m.getDocumentNumber());
response.setOrganizationCompleteName(m.getOrganizationName());
headerReponse.add(response);
});
System.out.println(Util.printAsJson(headerReponse));
Output:
[]
I'm trying to add the data result from response to a set
that is why I'm iterating. I don't know what I'm missing or if my approach is wrong.