Skip to content

Commit 70481e3

Browse files
Json Deserialization method was not applying the correct DateTimeFormat (#532)
* Json Deserialization mehotd was not applying the same DateTimeFormat as Serialization method. * Add unit test for cookie container serialization.
1 parent 1c2a57f commit 70481e3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

dotnet/src/dotnetframework/GxClasses/Helpers/JSONHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ public static T Deserialize<T>(string kbObject, Encoding encoding, IEnumerable<T
280280
{
281281
try
282282
{
283+
var settings = SerializationSettings(knownTypes);
283284
using (MemoryStream stream = new MemoryStream(encoding.GetBytes(kbObject)))
284285
{
285-
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T), knownTypes);
286+
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T), settings);
286287
#pragma warning disable SCS0028 // Unsafe deserialization possible from {1} argument passed to '{0}'
287288
return (T)serializer.ReadObject(stream);
288289
#pragma warning restore SCS0028 // Unsafe deserialization possible from {1} argument passed to '{0}'

dotnet/test/DotNetCoreUnitTest/Serialization.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Net;
34
using System.Text;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using GeneXus.Application;
78
using GeneXus.Encryption;
89
using GeneXus.Http;
9-
using GeneXus.Utils;
1010
using Microsoft.AspNetCore.Http;
1111
using Xunit;
1212

@@ -22,6 +22,15 @@ public async Task TestSessionRenew()
2222

2323
await authMiddleware.Invoke(httpContext);
2424
}
25+
[Fact]
26+
public async Task TestSessionCookieContainer()
27+
{
28+
var httpContext = new DefaultHttpContext() { Session = new MockHttpSession() };
29+
var authMiddleware = new MyAuthMiddleware(next: (innerHttpContext) => Task.FromResult(0));
30+
31+
await authMiddleware.SessionCookieContainerSerialization(httpContext);
32+
}
33+
2534
}
2635
public class MyAuthMiddleware
2736
{
@@ -31,6 +40,22 @@ public MyAuthMiddleware(RequestDelegate next)
3140
{
3241
_next = next;
3342
}
43+
public async Task SessionCookieContainerSerialization(HttpContext context)
44+
{
45+
GxContext gxcontext = new GxContext();
46+
gxcontext.HttpContext = context;
47+
string url = "https://test.net";
48+
CookieContainer container = gxcontext.GetCookieContainer(url, true);
49+
Cookie cookie = new Cookie("ROUTEID", ".http3");
50+
cookie.Path = "/";
51+
cookie.Expires = DateTime.MinValue;
52+
cookie.Domain = "test.net";
53+
container.Add(cookie);
54+
gxcontext.UpdateSessionCookieContainer();
55+
container = gxcontext.GetCookieContainer(url, true);
56+
Assert.Equal(1, container.Count);
57+
await _next(context);
58+
}
3459

3560
public async Task Invoke(HttpContext context)
3661
{

0 commit comments

Comments
 (0)