We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How define type in runtime for ReportingEngine

Hello.

I have next method
public Object getValue(String attribute)
and this method can return different types (String, Long, Double) depending on attribute;
And I use ReportingEngine for word template and inside of template I execute getValue which return Long.
I need find sum of 2 values
<<[content.getValue (“number”) + content.getValue (“number”)]>>
And I have next exception
java.lang.IllegalStateException: An error has been encountered at the end of expression ‘content.getValue (“number”) + content.getValue (“number”)’. Can not apply operator ‘+’ to operands of type ‘class java.lang.Object’ and ‘class java.lang.Object’.
If we change signature for public Long getValue(String attribute) it works correct.
So is it possible return Object but check real type in runtime and if it possible use corresponded function (like + or - or other methods related to long)?

Regards,
Anton

@Anton_Lytvyn,

Please also ZIP and attach your simplified template document and runnable Java application (source code without compilation errors) that helps us to reproduce this issue on our end. We will then investigate the issue on our end and provide you more information.

asposetest.zip (13.4 KB)

I provided 2 templates. One working example and second throws exception. So is it possible to fix second template without changing signature of getValue method?

@Anton_Lytvyn,

Thanks for the additional information. We have logged your requirement in our issue tracking system. The ID of your ticket is WORDSNET-17506. We will further look into the details of this problem and will keep you posted on further updates.

@Anton_Lytvyn,

We have modified your template document (see template2modified.zip (5.4 KB)) to make it work as expected. Please also note that class Long should be made known by the engine before building a report as follows.

ReportingEngine.getKnownTypes().add(Long.class);

For more information, see “Setting up Known External Types” section of documentation. Hope, this helps.

Thanks for your solution. But in my case I don’t know exactly what type will return method. So I can not cast type manually in template. It can be different type denends on parameter of method. Is it possible to define type in runtime?

@Anton_Lytvyn,

We have noted these details and will keep you posted on further updates.