Free Support Forum - aspose.com

Set JSON Simple Value Parse Mode to Strict | Avoid Formatting String of JsonDatasource as Number | LINQ Reporting Java

Hi,

When using a JsonDatasource, which has some string properties, Aspose.Words is interpreting them as numbers and adding a redundant .0 at the end of some strings. This is strange and unwanted behavior. A string is a string and should be treated as such.

From left to right: JsonDatasource - Expected output - Current output

jsondatasource.png (40.7 KB)

Here is an example application:

example-jsondatasource.zip (43.5 KB)

@mvHive,

We have logged this problem in our issue tracking system. Your ticket number is WORDSNET-22194. We will further look into the details of this problem and will keep you updated here on the status of the linked issue. We apologize for your inconvenience.

@mvHive,

During further investigation, it turns out to be an expected behavior rather than a bug. Please use the following code to fix the issue on your end.

JsonDataLoadOptions options = new JsonDataLoadOptions();
options.setSimpleValueParseMode(JsonSimpleValueParseMode.STRICT);
JsonDataSource dataSource = new JsonDataSource(..., options);

Complete code is as follows:

Document doc = new Document("C:\\Temp\\example-jsondatasource\\itemJson.docx");
ReportingEngine engine = getReportingEngine();
JsonDataSource order = createOrderWithThreeOrderLines();
Object[] sources = new Object[]{order};
String[] names = new String[]{"o"};
engine.buildReport(doc, sources, names);
doc.save("c:\\temp\\example-jsondatasource\\awjava-21.4.docx");

private static JsonDataSource createOrderWithThreeOrderLines() throws Exception {
    JsonDataLoadOptions options = new JsonDataLoadOptions();
    options.setSimpleValueParseMode(JsonSimpleValueParseMode.STRICT);

    return new JsonDataSource("C:\\Temp\\example-jsondatasource\\JsonDatasource.json", options);
}

private static ReportingEngine getReportingEngine() {
    ReportingEngine engine = new ReportingEngine();
    engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
    engine.getKnownTypes().add(BigDecimal.class);
    engine.getKnownTypes().add(Double.class);
    engine.getKnownTypes().add(Integer.class);
    engine.getKnownTypes().add(String.class);
    return engine;
}

More details can be found at the end of the article here: Accessing JSON Data.

Perfect. Thanks for the quick help @awais.hafeez