Hi,
I’m using the LINQ engine to create a word document, through a json file. I use java, and Aspose version 21.11. I would like to access a field only when other than null, so:
<< if [saldo.atStrumentiByCodStrum !=null]>>
<< [saldo.atStrumentiByCodStrum.desShort]>>
<< /if >>
but I have a nullPointerException at runtime.
resources.zip (239.3 KB)
@Blegork
Internally, JSON objects are deserialized into ADO.NET objects (in Java, you can find those within the com.aspose.words.net.System.Data
package). In you example, atStrumentiByCodStrum
is deserialized into a collection of rows related to the children
table. Although atStrumentiByCodStrum
is set to null for the first item in your JSON file, internally, it becomes an empty collection of rows that is not null, so comparison against null does not work.
To access desShort
only when atStrumentiByCodStrum
represents a non-empty collection of rows, you can use the following syntax:
<<if [saldo.atStrumentiByCodStrum.count() == 1]>>
<<[saldo.atStrumentiByCodStrum.desShort]>>
<</if>>
I have modified your template to show this. Please check testJsonNull Modified.docx (248.0 KB).