Annotate for trim/AOT (in)compatibility (#2980)

Co-authored-by: James Newton-King <james@newtonking.com>
This commit is contained in:
Sven Boemer
2024-10-11 16:33:15 +08:00
committed by GitHub
co-authored by James Newton-King
parent 4738a64817
commit 9317d71ac5
76 changed files with 1233 additions and 60 deletions
@@ -64,6 +64,8 @@ namespace Newtonsoft.Json.Serialization
{
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public void Populate(JsonReader reader, object target)
{
ValidationUtils.ArgumentNotNull(target, nameof(target));
@@ -139,6 +141,8 @@ namespace Newtonsoft.Json.Serialization
return Serializer._contractResolver.ResolveContract(type);
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public object? Deserialize(JsonReader reader, Type? objectType, bool checkAdditionalContent)
{
if (reader == null)
@@ -204,6 +208,8 @@ namespace Newtonsoft.Json.Serialization
}
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private JsonSerializerProxy GetInternalSerializer()
{
if (InternalSerializer == null)
@@ -292,6 +298,8 @@ namespace Newtonsoft.Json.Serialization
}
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object? CreateValueInternal(JsonReader reader, Type? objectType, JsonContract? contract, JsonProperty? member, JsonContainerContract? containerContract, JsonProperty? containerMember, object? existingValue)
{
if (contract != null && contract.ContractType == JsonContractType.Linq)
@@ -424,6 +432,8 @@ namespace Newtonsoft.Json.Serialization
return converter;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object? CreateObject(JsonReader reader, Type? objectType, JsonContract? contract, JsonProperty? member, JsonContainerContract? containerContract, JsonProperty? containerMember, object? existingValue)
{
string? id;
@@ -598,6 +608,8 @@ namespace Newtonsoft.Json.Serialization
throw JsonSerializationException.Create(reader, message);
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private bool ReadMetadataPropertiesToken(JTokenReader reader, ref Type? objectType, ref JsonContract? contract, JsonProperty? member, JsonContainerContract? containerContract, JsonProperty? containerMember, object? existingValue, out object? newValue, out string? id)
{
id = null;
@@ -685,6 +697,8 @@ namespace Newtonsoft.Json.Serialization
return false;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private bool ReadMetadataProperties(JsonReader reader, ref Type? objectType, ref JsonContract? contract, JsonProperty? member, JsonContainerContract? containerContract, JsonProperty? containerMember, object? existingValue, out object? newValue, out string? id)
{
id = null;
@@ -840,6 +854,8 @@ namespace Newtonsoft.Json.Serialization
return arrayContract;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object? CreateList(JsonReader reader, Type? objectType, JsonContract? contract, JsonProperty? member, object? existingValue, string? id)
{
object? value;
@@ -938,6 +954,8 @@ namespace Newtonsoft.Json.Serialization
);
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object? EnsureType(JsonReader reader, object? value, CultureInfo culture, JsonContract? contract, Type? targetType)
{
if (targetType == null)
@@ -1009,6 +1027,8 @@ namespace Newtonsoft.Json.Serialization
return value;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private bool SetPropertyValue(JsonProperty property, JsonConverter? propertyConverter, JsonContainerContract? containerContract, JsonProperty? containerProperty, JsonReader reader, object target)
{
bool skipSettingProperty = CalculatePropertyDetails(
@@ -1215,6 +1235,7 @@ namespace Newtonsoft.Json.Serialization
return true;
}
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private IList CreateNewList(JsonReader reader, JsonArrayContract contract, out bool createdFromNonDefaultCreator)
{
// some types like non-generic IEnumerable can be serialized but not deserialized
@@ -1283,6 +1304,7 @@ namespace Newtonsoft.Json.Serialization
}
}
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private IDictionary CreateNewDictionary(JsonReader reader, JsonDictionaryContract contract, out bool createdFromNonDefaultCreator)
{
if (contract.OverrideCreator != null)
@@ -1351,6 +1373,8 @@ namespace Newtonsoft.Json.Serialization
contract.InvokeOnDeserialized(value, Serializer._context);
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty? containerProperty, string? id)
{
object underlyingDictionary = dictionary is IWrappedDictionary wrappedDictionary ? wrappedDictionary.UnderlyingDictionary : dictionary;
@@ -1474,6 +1498,8 @@ namespace Newtonsoft.Json.Serialization
return underlyingDictionary;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object PopulateMultidimensionalArray(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty? containerProperty, string? id)
{
int rank = contract.UnderlyingType.GetArrayRank();
@@ -1624,6 +1650,8 @@ namespace Newtonsoft.Json.Serialization
}
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty? containerProperty, string? id)
{
#pragma warning disable CS8600, CS8602, CS8603, CS8604
@@ -1726,6 +1754,8 @@ namespace Newtonsoft.Json.Serialization
}
#if HAVE_BINARY_SERIALIZATION
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty? member, string? id)
{
Type objectType = contract.UnderlyingType;
@@ -1798,6 +1828,8 @@ namespace Newtonsoft.Json.Serialization
return createdObject;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
internal object? CreateISerializableItem(JToken token, Type type, JsonISerializableContract contract, JsonProperty? member)
{
JsonContract? itemContract = GetContractSafe(type);
@@ -1822,6 +1854,8 @@ namespace Newtonsoft.Json.Serialization
#endif
#if HAVE_DYNAMIC
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object CreateDynamic(JsonReader reader, JsonDynamicContract contract, JsonProperty? member, string? id)
{
IDynamicMetaObjectProvider newObject;
@@ -1948,6 +1982,8 @@ namespace Newtonsoft.Json.Serialization
}
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty? containerProperty, ObjectConstructor<object> creator, string? id)
{
ValidationUtils.ArgumentNotNull(creator, nameof(creator));
@@ -2182,6 +2218,8 @@ namespace Newtonsoft.Json.Serialization
return createdObject;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object? DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, object? existingValue)
{
if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Info)
@@ -2199,6 +2237,8 @@ namespace Newtonsoft.Json.Serialization
return value;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private List<CreatorPropertyContext> ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty? containerProperty, JsonReader reader, Type objectType)
{
List<CreatorPropertyContext> propertyValues = new List<CreatorPropertyContext>();
@@ -2298,6 +2338,8 @@ namespace Newtonsoft.Json.Serialization
return propertyValues;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public object CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty? containerMember, JsonProperty? containerProperty, string? id, out bool createdFromNonDefaultCreator)
{
object? newObject = null;
@@ -2341,6 +2383,8 @@ namespace Newtonsoft.Json.Serialization
return newObject;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object PopulateObject(object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty? member, string? id)
{
OnDeserializing(reader, contract, newObject);
@@ -2509,6 +2553,8 @@ namespace Newtonsoft.Json.Serialization
return false;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private void SetExtensionData(JsonObjectContract contract, JsonProperty? member, JsonReader reader, string memberName, object o)
{
if (contract.ExtensionDataSetter != null)
@@ -2530,6 +2576,8 @@ namespace Newtonsoft.Json.Serialization
}
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private object? ReadExtensionDataValue(JsonObjectContract contract, JsonProperty? member, JsonReader reader)
{
object? value;
@@ -2544,6 +2592,8 @@ namespace Newtonsoft.Json.Serialization
return value;
}
[RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
[RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private void EndProcessProperty(object newObject, JsonReader reader, JsonObjectContract contract, int initialDepth, JsonProperty property, PropertyPresence presence, bool setDefaultValue)
{
if (presence == PropertyPresence.None || presence == PropertyPresence.Null)