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")] [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) => private static JsonSerializerOptions CreateDefaultJsonSerializerOptions(bool writeIndented = false) {
new(JsonSerializerDefaults.Strict) { JsonSerializerOptions result = new(JsonSerializerDefaults.Strict) {
AllowTrailingCommas = true, AllowTrailingCommas = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
IndentCharacter = '\t', IndentCharacter = '\t',
@@ -129,6 +129,11 @@ public static class JsonUtilities {
WriteIndented = writeIndented 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", "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")] [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) { private static MethodInfo? GetShouldSerializeMethod([SuppressMessage("ReSharper", "SuggestBaseTypeForParameter")] Type parent, JsonPropertyInfo property) {