Can not get the value of member upon building reort

Hi @tahir.manzoor and team,

Based on the original author, I tried Java 24.1 and 21.2, seems this issue is not fixed. Can you please have a look and provide fix?

Exact same error as original author reported.

InputStream docx = this.getClass().getClassLoader().getResourceAsStream("test.docx");
Document doc = new Document(docx);
String json = "{\"landlord\" : {\"name\" : \"Test Test\"}}";
JsonDataSource jsonDataSource = new JsonDataSource(new ByteArrayInputStream(json.getBytes()));
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, jsonDataSource, "data");
doc.save("test_parsed.docx");
An error has been encountered at the end of expression 'data.landlord.n'. Can not get the value of member 'landlord' on type 'class com.aspose.words.net.System.Data.DataRow'.

Cheers,

@roy.jin In your case you should specify JsonDataLoadOptions.AlwaysGenerateRootObject option. Please see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("<<[data.landlord.name]>>");
String json = "{\"landlord\" : {\"name\" : \"Test Test\"}}";
JsonDataLoadOptions opt = new JsonDataLoadOptions();
opt.setAlwaysGenerateRootObject(true);
JsonDataSource jsonDataSource = new JsonDataSource(new ByteArrayInputStream(json.getBytes()), opt);
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, jsonDataSource, "data");
doc.save("C:\\Temp\\out.docx");
1 Like

Thank you for your help. It works.
Cheers,

1 Like