Smart marker with nested objects (map / list) fail to work with horizontal parameter

Hi,

I’m working with a Json data with nested objects that fail to work with horizontal parameter. It returns some internal reference instead of the actual data: (e.g. com.aspose.cells.t_e@6179e425)

Here is a code snippet that I was working with:

    try {
      Workbook workbook = new Workbook();
      Worksheet worksheet = workbook.getWorksheets().get(0);
      worksheet.setName("Sheet1");
      worksheet.getCells().get("A1").setValue("&=test.name.citations.filename");

      ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
      workbook.save(outputStream, com.aspose.cells.SaveFormat.XLSX);

      WorkbookDesigner designer = new WorkbookDesigner();
      designer.setWorkbook(workbook);

      designer.setJsonDataSource("test", "{\"name\": {\"citations\": [{\"filename\": \"doc.pdf\"}, {\"filename\": \"doc2.pdf\"}]}}");
      designer.process();

      Range range = worksheet.getCells().getMaxDisplayRange();
      int cols = range.getColumnCount();
      int rows = range.getRowCount();
      for (int i = 0 ; i < rows ; i++) {
        for (int j = 0 ; j < cols ; j++) {
          logger.info("{} - {}", worksheet.getCells().get(i,j).getName(), worksheet.getCells().get(i,j).getValue());
        }
      }
    } catch (Exception e) {
      logger.error("Failed: {}, {}", e.getMessage(), e.getStackTrace());
      throw e;
    }

The code as is works as expected. It prints:

A1 - doc.pdf
A2 - doc2.pdf

When I apply horizontal parameter to the template: "&=test.name.citations.filename(horizontal)", it prints:

A1 - com.aspose.cells.t_e@6179e425

Is this an expected behavior?

@yoohee

The behavior you’re experiencing with the horizontal parameter in your smart marker is expected when dealing with nested objects in JSON. The horizontal parameter attempts to flatten the data structure, but it appears that the nested list is not being processed correctly, resulting in the internal reference being displayed instead of the actual data.

To resolve this issue, consider the following steps:

  1. Ensure that your JSON structure is correctly formatted and that the smart marker is properly defined in your template.
  2. If the horizontal parameter does not yield the expected results, you may need to process the data without it or restructure your JSON to better fit the expected format for horizontal processing.

Here’s a modified approach that does not use the horizontal parameter:

designer.setJsonDataSource("test", "{\"name\": {\"citations\": [{\"filename\": \"doc.pdf\"}, {\"filename\": \"doc2.pdf\"}]}}");
designer.process();

If you need to display the filenames horizontally, you will need to manually iterate through the list and set the values in the cells accordingly.

For further assistance, please consult the official Aspose.Cells documentation on smart markers and JSON data sources.

@yoohee
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-46511

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.