Skip to content

Commit

Permalink
(#14) nuar: udpate object population and serialization in payload tra…
Browse files Browse the repository at this point in the history
…nsformer [pack-all-force]
  • Loading branch information
SaintAngeLs committed Sep 29, 2024
1 parent 98aec01 commit 2f8de9e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
15 changes: 4 additions & 11 deletions src/Nuar/src/Nuar/Requests/PayloadTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json;
using NetJSON;
using Nuar.Options;
using Route = Nuar.Configuration.Route;

Expand All @@ -27,25 +27,21 @@ public PayloadTransformer(NuarOptions options, IPayloadManager payloadManager, I

public bool HasTransformations(string resourceId, Route route)
{
// Check if resourceId is not null or empty
if (!string.IsNullOrWhiteSpace(resourceId))
{
return true;
}

// Check if 'Bind' collection in the route is not null or has any elements
if (route.Bind != null && route.Bind.Any())
{
return true;
}

// Check if 'Transform' collection in the route is not null or has any elements
if (route.Transform != null && route.Transform.Any())
{
return true;
}

// Check if payloads dictionary contains the key for the route
return _payloads.ContainsKey(GetPayloadKey(route));
}

Expand Down Expand Up @@ -106,11 +102,11 @@ public PayloadSchema Transform(string payload, string resourceId, Route route, H
private object GetObjectFromPayload(Route route, string content)
{
var payloadValue = _payloads[GetPayloadKey(route)].Payload;
var request = JsonConvert.DeserializeObject(content, payloadValue.GetType());
var request = NetJSON.NetJSON.Deserialize(payloadValue.GetType(), content);
var payloadValues = (IDictionary<string, object>)payloadValue;
var requestValues = (IDictionary<string, object>)request;

foreach (var key in requestValues.Keys)
foreach (var key in requestValues.Keys.ToList()) // Avoid modifying the collection while enumerating
{
if (!payloadValues.ContainsKey(key))
{
Expand All @@ -123,10 +119,7 @@ private object GetObjectFromPayload(Route route, string content)

private static object GetObject(string content)
{
dynamic payload = new ExpandoObject();
JsonConvert.PopulateObject(content, payload);

return JsonConvert.DeserializeObject(content, payload.GetType());
return NetJSON.NetJSON.Deserialize<ExpandoObject>(content);
}

private string GetPayloadKey(Route route) => _payloadManager.GetKey(route.Method, route.Upstream);
Expand Down
2 changes: 1 addition & 1 deletion src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[assembly: System.Reflection.AssemblyCopyrightAttribute("ITSharpPro © ")]
[assembly: System.Reflection.AssemblyDescriptionAttribute("Nuar - A framework for building API gateways in a microservices architecture")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+837a033c257f83360d53d4f84b8680351db2bc22")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+98aec01653883b77d79363dc0cb9c8642aed0ee1")]
[assembly: System.Reflection.AssemblyProductAttribute("Nuar")]
[assembly: System.Reflection.AssemblyTitleAttribute("Nuar")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bf7838e570ccb34e214d40d42cf8e92986e65d505e16be33e08545555d941eea
f5657c688c2db74647cbb018bce61daf836b7962dd555a348e867b98a4cf9c62

0 comments on commit 2f8de9e

Please sign in to comment.