disabled null values serialization
This commit is contained in:
parent
d70b605127
commit
da27f84d68
@ -1,6 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using DTLib.Extensions;
|
||||
|
||||
namespace ParadoxSaveParser.Lib.Tests;
|
||||
@ -22,7 +23,8 @@ public class SearchExpressionTests
|
||||
{
|
||||
WriteIndented = false,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
MaxDepth = 1024
|
||||
MaxDepth = 1024,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
};
|
||||
|
||||
internal static string JsonToPdx(string json)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ParadoxSaveParser.WebAPI.BackgroundTasks;
|
||||
|
||||
@ -15,9 +16,10 @@ public class SaveParsingOperation
|
||||
|
||||
private static readonly JsonSerializerOptions _saveSerializerOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
WriteIndented = false,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
MaxDepth = 1024
|
||||
MaxDepth = 1024,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
};
|
||||
|
||||
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.Json.Serialization;
|
||||
using DTLib.Extensions;
|
||||
|
||||
namespace ParadoxSaveParser.WebAPI.HttpHelpers;
|
||||
@ -10,7 +12,8 @@ public class ReturnHelper
|
||||
{
|
||||
WriteIndented = false,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
MaxDepth = 1024
|
||||
MaxDepth = 1024,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
};
|
||||
|
||||
private static async Task ResponseShort(HttpListenerContext ctx,
|
||||
@ -22,7 +25,7 @@ public class ReturnHelper
|
||||
{
|
||||
ctx.Response.StatusCode = (int)statusCode;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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; }
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
@ -36,6 +40,6 @@ public class SaveFileMetadata
|
||||
public void SaveToFile()
|
||||
{
|
||||
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