Do not allow plugins to modify default ASF json serializer settings upon creation

This can only accidentally break things we expect to be operative
This commit is contained in:
Łukasz Domeradzki
2025-12-28 01:04:44 +01:00
parent 10a7fe157b
commit d75028a1e9

View File

@@ -116,8 +116,8 @@ public static class JsonUtilities {
}
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
private static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool writeIndented = false) =>
new(JsonSerializerDefaults.Strict) {
private static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool writeIndented = false) {
JsonSerializerOptions result = new(JsonSerializerDefaults.Strict) {
AllowTrailingCommas = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
IndentCharacter = '\t',
@@ -129,6 +129,11 @@ public static class JsonUtilities {
WriteIndented = writeIndented
};
result.MakeReadOnly();
return result;
}
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2070", Justification = "We don't care about trimmed methods, it's not like we can make it work differently anyway")]
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2075", Justification = "We don't care about trimmed properties, it's not like we can make it work differently anyway")]
private static MethodInfo? GetShouldSerializeMethod([SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")] Type parent, JsonPropertyInfo property) {