Page 1 of 2

Register Business Object with nested objects as JToken

Posted: Thu Oct 01, 2020 12:16 pm
by Ruslan Kadyrbaev
Hello all,

I need to pass objects as json string and bind to business object.
Then I have a code which register business object as "JToken"

Code: Select all

                var jsonObject = StimulsoftJToken.Parse(json);
                report.RegBusinessObject(category: dataObject.Category, name: dataObject.Name, alias: dataObject.Alias, value: jsonObject);
This code works fine with simple objects with a flat structure (no nested objects)

But is not working with objects with nested objects (rendered properties are empty)

Also if I try to use explicit C# objects instead of JToken - report works fine

Code: Select all

        private class Receipt
        {
            public Payment Payment { get; set; }

            public Payer Payer { get; set; }

            public string Name { get; set; } // this works fine
        }

        private class Payment
        {
            public string Note { get; set; } // it is empty
        }

        private class Payer
        {
            public string Name { get; set; } // it is empty
        }
How I can bind dynamic objects (like JToken or simple json string)?

P.S. .Net Core 3.1 with Linux

Re: Register Business Object with nested objects as JToken

Posted: Thu Oct 01, 2020 3:36 pm
by Lech Kulikowski
Hello,

Please try to add the Synchronize() method:
report.Dictionary.SynchronizeBusinessObjects(nestedlevels);

Thank you.

Re: Register Business Object with nested objects as JToken

Posted: Fri Oct 02, 2020 6:42 am
by Ruslan Kadyrbaev
Lech Kulikowski wrote: Thu Oct 01, 2020 3:36 pm Hello,

Please try to add the Synchronize() method:
report.Dictionary.SynchronizeBusinessObjects(nestedlevels);

Thank you.
I already tried that solution a time ago. But I get an error.
Could you explain how to fix it?
Engine version 2020.3.2 and 2020.4.2, .Net Core 3.1 on Linux

Code: Select all

Object reference not set to an instance of an object. StackTrace:    at Stimulsoft.Report.Dictionary.StiBusinessObjectHelper.GetValueFromITypedList(ITypedList typedList, String name)
   at Stimulsoft.Report.Dictionary.StiBusinessObjectHelper.GetElementFromObject(Object value, String name, Boolean isColumnsRetrieve)
   at Stimulsoft.Report.Dictionary.StiBusinessObject.GetBusinessObjectData(Boolean isColumnsRetrieve)
   at Stimulsoft.Report.Dictionary.StiDictionary.Synchronize(StiBusinessObjectsCollection businessObjects)
   at Stimulsoft.Report.Dictionary.StiDictionary.SynchronizeBusinessObjects()
   at Stimulsoft.Report.Dictionary.StiDictionary.Synchronize()
   at Stimulsoft.Report.Dictionary.StiDictionary.<SynchronizeAsync>b__104_0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Stimulsoft.Report.Dictionary.StiDictionary.SynchronizeAsync()
Full code

Code: Select all

            using var report = new StiReport();
            report.Load(templateBody); // body as byte[]
            report.CacheAllData = false;

            var jsonObject = StimulsoftJToken.Parse(json); // json
            report.RegBusinessObject(category: dataObject.Category, name: dataObject.Name, alias: dataObject.Alias, value: jsonObject);

            // sync data & render
            await report.Dictionary.SynchronizeAsync();
            await report.RenderAsync(new StiRenderState(false));
Json data

Code: Select all

[{
    "Payment": {
      "Name": "123",
      "rub": "123",
      "penny": "123",
      "rubCom": "123",
      "pennyCom": "123",
      "rubTotal": "123",
      "pennyTotal": "123",
      "day": "1",
      "month": "1",
      "year": "2020"
    },
    "Payer": {
      "firstName": "PayerName1",
      "lastName": "PayerName2",
      "middleName": "qwe",
      "address": "qwe"
    },
    "Name": "qwe",
    "inn": "123123",
    "bankAccount": "123123",
    "bankName": "qwe",
    "bic": "123123",
    "bankCorrAccount": "123123"
  }]
Report file was attached
ReceiptPD4.mrt
(6.71 KiB) Downloaded 373 times

Re: Register Business Object with nested objects as JToken

Posted: Fri Oct 02, 2020 7:31 am
by Lech Kulikowski
Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.

Re: Register Business Object with nested objects as JToken

Posted: Fri Oct 02, 2020 7:32 am
by Lech Kulikowski
Hello,

Also, in your code is used
await report.Dictionary.SynchronizeAsync();
but for business object, you should use
report.Dictionary.SynchronizeBusinessObjects(nestedlevels);

Thank you.

Re: Register Business Object with nested objects as JToken

Posted: Fri Oct 02, 2020 8:34 am
by Ruslan Kadyrbaev
Lech Kulikowski wrote: Fri Oct 02, 2020 7:31 am Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.
There is

https://github.com/ruslankadyrbaev/Stim ... Program.cs

Re: Register Business Object with nested objects as JToken

Posted: Fri Oct 02, 2020 8:38 am
by Ruslan Kadyrbaev
Lech Kulikowski wrote: Fri Oct 02, 2020 7:32 am Hello,

Also, in your code is used
await report.Dictionary.SynchronizeAsync();
but for business object, you should use
report.Dictionary.SynchronizeBusinessObjects(nestedlevels);

Thank you.
await report.Dictionary.SynchronizeAsync(); directly calls report.Dictionary.SynchronizeBusinessObjects by himself
Also you can check the stack trace - there is same situation

Re: Register Business Object with nested objects as JToken

Posted: Mon Oct 05, 2020 1:26 pm
by Lech Kulikowski
Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.

Re: Register Business Object with nested objects as JToken

Posted: Wed Oct 14, 2020 7:06 am
by Ruslan Kadyrbaev
Lech Kulikowski wrote: Mon Oct 05, 2020 1:26 pm Hello,

We need some additional time to investigate the issue, we will let you know about the result.

Thank you.
Hello,

Are there any updates?

Re: Register Business Object with nested objects as JToken

Posted: Sat Oct 17, 2020 5:35 pm
by Lech Kulikowski
Hello,

We work hard on this problem and do our best to do it as fast as possible. We will let you know when the solution is available.

Thank you.
#2871