disabled null values serialization
This commit is contained in:
parent
d70b605127
commit
da27f84d68
@ -1,6 +1,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using DTLib.Extensions;
|
using DTLib.Extensions;
|
||||||
|
|
||||||
namespace ParadoxSaveParser.Lib.Tests;
|
namespace ParadoxSaveParser.Lib.Tests;
|
||||||
@ -22,7 +23,8 @@ public class SearchExpressionTests
|
|||||||
{
|
{
|
||||||
WriteIndented = false,
|
WriteIndented = false,
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
MaxDepth = 1024
|
MaxDepth = 1024,
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||||
};
|
};
|
||||||
|
|
||||||
internal static string JsonToPdx(string json)
|
internal static string JsonToPdx(string json)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace ParadoxSaveParser.WebAPI.BackgroundTasks;
|
namespace ParadoxSaveParser.WebAPI.BackgroundTasks;
|
||||||
|
|
||||||
@ -15,9 +16,10 @@ public class SaveParsingOperation
|
|||||||
|
|
||||||
private static readonly JsonSerializerOptions _saveSerializerOptions = new()
|
private static readonly JsonSerializerOptions _saveSerializerOptions = new()
|
||||||
{
|
{
|
||||||
WriteIndented = true,
|
WriteIndented = false,
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
MaxDepth = 1024
|
MaxDepth = 1024,
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||||
};
|
};
|
||||||
|
|
||||||
public SaveParsingOperation(long operationId, SaveFileMetadata meta, ISearchExpression searchQuery,
|
public SaveParsingOperation(long operationId, SaveFileMetadata meta, ISearchExpression searchQuery,
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
using System.Net;
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using DTLib.Extensions;
|
using DTLib.Extensions;
|
||||||
|
|
||||||
namespace ParadoxSaveParser.WebAPI.HttpHelpers;
|
namespace ParadoxSaveParser.WebAPI.HttpHelpers;
|
||||||
@ -10,7 +12,8 @@ public class ReturnHelper
|
|||||||
{
|
{
|
||||||
WriteIndented = false,
|
WriteIndented = false,
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
MaxDepth = 1024
|
MaxDepth = 1024,
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||||
};
|
};
|
||||||
|
|
||||||
private static async Task ResponseShort(HttpListenerContext ctx,
|
private static async Task ResponseShort(HttpListenerContext ctx,
|
||||||
@ -22,7 +25,7 @@ public class ReturnHelper
|
|||||||
{
|
{
|
||||||
ctx.Response.StatusCode = (int)statusCode;
|
ctx.Response.StatusCode = (int)statusCode;
|
||||||
ctx.Response.ContentType = contentType;
|
ctx.Response.ContentType = contentType;
|
||||||
logger.LogDebug($"response (length: {value.Length} type: {contentType})");
|
logger.LogDebug($"short response (length: {value.Length} type: {contentType})");
|
||||||
if (value.Length > 4000)
|
if (value.Length > 4000)
|
||||||
{
|
{
|
||||||
logger.LogWarn($"response (length: {value.Length} type: {contentType})\n"
|
logger.LogWarn($"response (length: {value.Length} type: {contentType})\n"
|
||||||
@ -67,4 +70,27 @@ public class ReturnHelper
|
|||||||
{
|
{
|
||||||
return await ResponseJson(ctx, logger, ct, error, error.StatusCode);
|
return await ResponseJson(ctx, logger, ct, error, error.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<HttpStatusCode> ResponseStream(HttpListenerContext ctx,
|
||||||
|
ContextLogger logger,
|
||||||
|
CancellationToken ct,
|
||||||
|
Stream valueStream,
|
||||||
|
HttpStatusCode statusCode = HttpStatusCode.OK,
|
||||||
|
string contentType = "application/octet-stream")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ctx.Response.StatusCode = (int)statusCode;
|
||||||
|
ctx.Response.ContentType = contentType;
|
||||||
|
logger.LogDebug($"stream response (type: {contentType})");
|
||||||
|
await valueStream.CopyToAsync(ctx.Response.OutputStream, ct);
|
||||||
|
return statusCode;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return await ResponseError(ctx, logger, ct,
|
||||||
|
new ErrorMessage(HttpStatusCode.InternalServerError,
|
||||||
|
ex.ToStringDemystified()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -20,7 +20,11 @@ public enum Game
|
|||||||
|
|
||||||
public class SaveFileMetadata
|
public class SaveFileMetadata
|
||||||
{
|
{
|
||||||
private static readonly JsonSerializerOptions _jsonOptions = new() { WriteIndented = true };
|
private static readonly JsonSerializerOptions _configSerializerOptions = new()
|
||||||
|
{
|
||||||
|
WriteIndented = true,
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||||
|
};
|
||||||
public required string id { get; init; }
|
public required string id { get; init; }
|
||||||
|
|
||||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||||
@ -36,6 +40,6 @@ public class SaveFileMetadata
|
|||||||
public void SaveToFile()
|
public void SaveToFile()
|
||||||
{
|
{
|
||||||
using var metaFile = File.OpenWrite(PathHelper.GetMetaFilePath(id));
|
using var metaFile = File.OpenWrite(PathHelper.GetMetaFilePath(id));
|
||||||
JsonSerializer.Serialize(metaFile, this, _jsonOptions);
|
JsonSerializer.Serialize(metaFile, this, _configSerializerOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user