Replies: 1 comment 1 reply
-
Can the code work with old reflection approach, instead of source generator? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello .Net team,
I've been trying out the new
System.Text.Json
source generator with the recently releasednet6.0-preview.7
and I have encountered few issues that I'm unable to solve.init
-only properties supported for deserialization using the newJsonTypeInfo
API? My use case is strongly typed configuration objects that are read from and written to a file. To reduce the overhead of reading values, I store the last instance in "cache". So to avoid mutating the current state, all properties are defined as{ get; init; }
.JsonSerializerContext
withJsonSerializableAttribute
, a property for the collection type is created, but fails at runtime, because it cannot be constructed. I've tried to manually addJsonTypeInfo<MyImmutableList>
to the serializer context, but then there is not way to add it to theJsonTypeInfo GetTypeInfo(Type type)
method, therefore the serializer cannot find my custom value.MyImmutableList
and annotate the type, but then I stumbled upon problem with serialization/deserialization of element types. In theRead/Write
methods ofJsonConverter<T>
I cannot find a way to resolveJsonTypeInfo
and resolving a converter by callingoptions.GetConverter(typeof(MyElement))
puts me back into square one withRequiresUnreferencedCode
warnings. I also cannot instantiate a new instance ofMyJsonContext
with the options passed into theJsonConverter<T>.Read/Write
methods, because each options instance can be associated only with one context.Minimal repro of my use case.
Beta Was this translation helpful? Give feedback.
All reactions