Conditional existance of nullable part of data model

Hello,

We have a use case where our data model is not able to use a common template because some part of the data model is nullable.

Let me show you what are our use cases.

Here is our template. (14.6 KB)

Our first data model which works perfectly.
{ "person1": { "name": "P1" }, "person2": { "name": "P2" } }

The second one which fails due to the “name” property which is not present.
{ "person1": { "name": "P1" }, "person2": null }

(Sorry haven’t been able to upload a JSON file).

Can GroupDocs assembly handle such a use case?

Kind regards.

1 Like

@ybenkh

We are investigating this scenario. Your investigation ticket ID is ASSEMBLYJAVA-31.

@ybenkh

This use-case is a perfect fit for using DocumentAssemblyOptions.ALLOW_MISSING_MEMBERS as follows:

DocumentAssembler assembler = new DocumentAssembler(); 
assembler.setOptions(DocumentAssemblyOptions.ALLOW_MISSING_MEMBERS); 
assembler.assembleDocument(...);

Wow, thanks a lot for your prompt reply.
I’ve just tested it and it works like a charm.

But I did not found anything related to that option in the documentation.
Did I miss something?

Thanks again.

Regards.

1 Like

@ybenkh

We will create a relevant documentation article and share with you.

@ybenkh

Please take a look at this documentation article.

Great! I just read it and sounds good.
IMO, the last sentence should have been highlighted:

However, if DocumentAssemblyOptions.ALLOW_MISSING_MEMBERS is applied, the assembler treats access to such a field as a null literal, so no exception is thrown and simply no value is written to the report then.

Regards.

1 Like

@ybenkh

Thanks for the feedback. We’ll look into it.