Java creating a JsonDataSource using a JsonNode object


I have the following use case: we have a JsonNode object coming from our persistence layer, we want to create a JsonDataSource using that JsonNode object before filling a Jasper Report. Now the question is: why do we have to convert that JsonNode to InputStream before creating the JsonDataSource? While checking the code source of the JsonDataSource class I can see the following constructor:

    protected JsonDataSource(JsonNode jsonTreeString selectExpressionthrows JRException {

But it is coded as protected and we can't call it in our case, we found out that converting the object to InputStream in order to use the public constructor, which will in fact convert the object back to a JsonNode, is not optimal and therefore I would like to know if there is any fix for this case?

public JsonDataSource(InputStream jsonStreamString selectExpressionthrows JRException {
        this(JsonUtil.parseJson(jsonStream), selectExpression);

Thank you for your efforts!

walid.asansas's picture
Joined: Nov 12 2020 - 8:10pm
Last seen: 2 years 6 months ago

0 Answers:

No answers yet