We use a custom data source multiple times throughout our report. In order to get the subsets of data from the main datasource that we need for each area of the report, we add methods to our data source that return a custom datasource with the required data. We then define a datasource expression for each section that gets report data source, casts it as our custom data source class, and then calls the appropriate method to return get the necessary datasource for that section. this works great to initially fill and render our report, but when we sort any records, we get an error that says "SortedDataSource can not be cast to [our custom data source]".
Does anyone know a way to guarantee retrieving the original data source?
Here are some additional general details about our custom data source, to help understand why we are trying to do what we are doing. The data source calls rest enpoints to retrieve data for which we do not have direct db access. The data is returned as Json which we deserialize into POJOs. For a single report, we would prefer not to make multiple rest calls to retrieve the data. Some of the records contain subordinate records, so we add methods to return the subordinate records as a separate data source for the areas of the report where they are needed.
1. Once sorted, you cannot retrieve your custom data source, unless you clone it and add it to the report as a parameter and get it from there.
Other options might be:
2. Presort your records in your custom datasource and avoid using sortFields
3. Use subreports or dataSet-based components like lists/table and use sortFields there.