-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Text.Json source generator JsonIgnoreCondition missing namespace #54385
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsDescriptionWhen using example classes: using System.Text.Json.Serialization;
namespace ConsoleApp3
{
[JsonSerializable(typeof(Test))]
internal partial class TestContext : JsonSerializerContext
{
}
} using System.Text.Json.Serialization;
namespace ConsoleApp3
{
public class Test
{
[JsonIgnore]
public int X { get; set; }
public int Y { get; set; }
}
}
error: generated: ignoreCondition: JsonIgnoreCondition.Always, expected: ignoreCondition: global::System.Text.Json.Serialization.JsonIgnoreCondition.Always, Configurationdotnet: 6.0.100-preview.5.21302.13 Other informationgenerated code // <auto-generated/>
namespace ConsoleApp3
{
internal partial class TestContext
{
private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::ConsoleApp3.Test> _Test;
public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::ConsoleApp3.Test> Test
{
get
{
if (_Test == null)
{
global::System.Text.Json.Serialization.JsonConverter customConverter;
if (Options.Converters.Count > 0 && (customConverter = GetRuntimeProvidedCustomConverter(typeof(global::ConsoleApp3.Test))) != null)
{
_Test = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::ConsoleApp3.Test>(Options, customConverter);
}
else
{
global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::ConsoleApp3.Test> objectInfo = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo<global::ConsoleApp3.Test>(
Options,
createObjectFunc: static () => new global::ConsoleApp3.Test(),
propInitFunc: TestPropInit,
default,
serializeFunc: TestSerialize);
_Test = objectInfo;
}
}
return _Test;
}
}
private static global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] TestPropInit(global::System.Text.Json.Serialization.JsonSerializerContext context)
{
global::ConsoleApp3.TestContext jsonContext = (global::ConsoleApp3.TestContext)context;
global::System.Text.Json.JsonSerializerOptions options = context.Options;
global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[] properties = new global::System.Text.Json.Serialization.Metadata.JsonPropertyInfo[2];
properties[0] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Int32>(
options,
isProperty: true,
declaringType: typeof(global::ConsoleApp3.Test),
propertyTypeInfo: jsonContext.Int32,
converter: null,
getter: static (obj) => { return ((global::ConsoleApp3.Test)obj).X; },
setter: static (obj, value) => { ((global::ConsoleApp3.Test)obj).X = value; },
ignoreCondition: JsonIgnoreCondition.Always,
numberHandling: default,
propertyName: "X",
jsonPropertyName: null);
properties[1] = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreatePropertyInfo<global::System.Int32>(
options,
isProperty: true,
declaringType: typeof(global::ConsoleApp3.Test),
propertyTypeInfo: jsonContext.Int32,
converter: null,
getter: static (obj) => { return ((global::ConsoleApp3.Test)obj).Y; },
setter: static (obj, value) => { ((global::ConsoleApp3.Test)obj).Y = value; },
ignoreCondition: default,
numberHandling: default,
propertyName: "Y",
jsonPropertyName: null);
return properties;
}
private static void TestSerialize(global::System.Text.Json.Utf8JsonWriter writer, global::ConsoleApp3.Test value)
{
if (value == null)
{
writer.WriteNullValue();
return;
}
writer.WriteStartObject();
writer.WriteNumber(XPropName, value.X);
writer.WriteNumber(YPropName, value.Y);
writer.WriteEndObject();
}
}
}
|
cc @layomia |
Description
When using
JsonIgnoreAttribute
withJsonSerializerContext
using Source Generators, generated code is not correctexample classes:
error:
error CS0103: The name 'JsonIgnoreCondition' does not exist in the current context
generated:
expected:
Configuration
dotnet: 6.0.100-preview.5.21302.13
System.Text.Json: 6.0.0-preview.5.21301.5
Other information
generated code
TestContext.Test.g.cs
The text was updated successfully, but these errors were encountered: