Return JsonElement in Response

This commit is contained in:
Behzad Alizadeh
2025-12-10 12:14:21 +03:30
parent 52466642ab
commit 179d1de763
2 changed files with 36 additions and 7 deletions
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using JetBrains.Annotations;
@@ -32,7 +33,7 @@ public class WorkflowModel
/// <summary>
/// داده صفحه جاری
/// </summary>
public string? CurrentPageData { get; set; }
public JsonElement? CurrentPageData { get; set; }
/// <summary>
/// داده صفحه بعد
@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Caspian.WorkflowFramework.Models;
@@ -32,13 +34,39 @@ public static class ConversionExtensions
? long.TryParse(dictionary[nameof(workflowModel.UserId)]?.ToString(), out var userId) ? userId : (long?)null
: null;
//workflowModel.CurrentPageData = dictionary.ContainsKey(nameof(workflowModel.CurrentPageData))
// ? (object?)dictionary[nameof(workflowModel.CurrentPageData)]
// : null;
if (dictionary.TryGetValue(nameof(workflowModel.CurrentPageData), out var currentPageDataObj) &&
currentPageDataObj is not null)
{
switch (currentPageDataObj)
{
case JsonElement je:
workflowModel.CurrentPageData = je;
break;
workflowModel.CurrentPageData = dictionary.ContainsKey(nameof(workflowModel.CurrentPageData))
? dictionary[nameof(workflowModel.CurrentPageData)]?.ToString()
: null;
case JsonNode node:
// .NET 6+
workflowModel.CurrentPageData = JsonSerializer.SerializeToElement(node);
break;
case string s:
// اگر به صورت string JSON ذخیره شده
workflowModel.CurrentPageData = JsonSerializer.Deserialize<JsonElement>(s);
break;
default:
// هر نوع دیگری: serialize و تبدیل به JsonElement
workflowModel.CurrentPageData = JsonSerializer.SerializeToElement(currentPageDataObj);
break;
}
}
else
{
workflowModel.CurrentPageData = null;
}
//workflowModel.CurrentPageData = dictionary.ContainsKey(nameof(workflowModel.CurrentPageData))
// ? dictionary[nameof(workflowModel.CurrentPageData)]?.ToString()
// : null;
//workflowModel.NextPageData = dictionary.ContainsKey(nameof(workflowModel.NextPageData))
// ? (object?)dictionary[nameof(workflowModel.NextPageData)]