Two decimal format is not working as expected for mixed data type json

Hi Team,
We are using Aspose Word 24.1 linq engine syntax for our word template where two decimal format is working when generating the documents and we are using Json Data source here.
here attached all the required data and in the images i highligted the value which is not coming in 2 decimal
asposeQuery.zip (21.5 KB)

@anupkrsinha Unfortunately, I cannot reproduce th eproblem on my side using the latest 27.7 version of Aspose.Words for java. I used the following code for testing:

JsonDataSource data = new JsonDataSource("C:\\Temp\\josn.json");
        
Document doc = new Document("C:\\Temp\\template.docx");
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, data, "IPlusCalendarYear");
doc.save("C:\\Temp\\out.docx");

Here is the produced output: out.docx (11.6 KB)

Somehow due to license issue i am unable to upgrade the aspose version, i am checking with the team on that, Meanwhile could you please try with 24.1 version and give us some solution for the same, as this is become blocker for us now

@anupkrsinha The problem is not reproducible with 24.1 on my side. Here is the produced output:out.docx (11.6 KB)

reason you are using options.setSimpleValueParseMode(0); and we set this value as 1 (- strict json match), so its not working at for us and we cannot change 1 to 0 at our side due to some constraints.
can you check now and provide some solution for this…

@anupkrsinha I am afraid there is no way to get the expected value with JsonSimpleValueParseMode.STRICT. In your JSON Year9 field, as well as other fields, has string type in the first row and double in the following. Since the same column in the data table cannot have different types, string type is used and as a result number format is not applied. When JsonSimpleValueParseMode.LOOSE mode is used, type of the columns is detected as double and format is applied properly.
As a workaround you can parse string value to double in your template:
<<[Double.parseDouble(item.Year9)]:"0.00">>

JsonDataLoadOptions opt = new JsonDataLoadOptions();
opt.setSimpleValueParseMode(JsonSimpleValueParseMode.STRICT);
JsonDataSource data = new JsonDataSource("C:\\Temp\\josn.json", opt);
    
Document doc = new Document("C:\\Temp\\template.docx");
ReportingEngine engine = new ReportingEngine();
engine.getKnownTypes().add(Double.class);
engine.buildReport(doc, data, "IPlusCalendarYear");
doc.save("C:\\Temp\\out.docx");

Thanks it works…

1 Like