OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.41k stars 2.39k forks source link

json filter [fluid] doesn't work with Workflow Input, Output, Properties dictionaries #8478

Open lampersky opened 3 years ago

lampersky commented 3 years ago

Describe the bug

When using json filter on Workflow object (WorkflowExecutionContext), everything seems to be fine, I'm getting nice string representation, but when I've tried with any of Workflow public member (Input, Output, Properties) I've got empty string.

image

To Reproduce

Steps to reproduce the behavior:

  1. Enable Workflow feature,
  2. Create new workflow as shown below (or use repro recipe Recipe.zip): image
  3. As a content for HttpResponseTask use:
    
    {{ Workflow.Output | json }}

{% assign workflow2 = Workflow | json | jsonparse %}

{{ workflow2.Output | json }}


4. **json** filter doesn't work with **Workflow.Output** (nor Input/Properties),
5. as a workaround you can serialize object to json string and then parse it back to object, and then use **json** filter,
6. **workflow2.Output** can be serialized to JSON string with any problems,
7. other than that, it would be nice to have iterating over dictionaries support from Fluid :)

### Expected behavior
json filter should be able to stringify Input, Output and Properties (Workflow's class members)
weirdyang commented 3 years ago

I encountered this the other day, I realised this is because the objects are stored as jObjects.
so for example:

A http request comes in with a body like:

{
   "data" : 1,
   "value" : "hello"
}

and you set it to workflow property - MyData using JSON.parse(readBody())

if you do {{ Workflow.Properties.MyData | json }}, you'll get this:

{
    "Count": 2,
    "Keys": [
        "data",
        "hello"
    ]
}

To access the values, you will need to use the keys eg. {{ Workflow.Properties.MyData["data"] }}