✅ .NET 8 enum to string serialization throws an exception
Hello,
Following the docs, a custom
JsonSerializerContext
is applied on the controllers, yet an exception is thrown.
The exception:
I have followed the docs:
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation#combine-source-generators
https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation#blanket-policyHow to use source generation in System.Text.Json - .NET
Learn how to use source generation in System.Text.Json.
9 Replies
'AnalyticsService.Api..'
doesn't strike me as a valid type identifier
especially that double dot at the end is mighty suspicious
whats the fully qualified name for GetLinkMetricsRequest
?sorry, I had no idea that's relevant
ok so its in that namespace at least
but that seems to be a generic version?
GetLinkMetricsResult<T>
That's being returned, specifically
GetLinkMetricsResult<LinkClicksByDateResult>
But there is no enum being used here
and it is the responsebut that type is what the serializer cant serialize
thats the error you are getting
meaning it (probably) handles the request fine, its the result thats failing
Yes, the result is failing
the request is serialized
okay, so add the result type to your serializer context?
Now it works, thank you, I still don't understand what has the response to do with the serializer
$close
If you have no further questions, please use /close to mark the forum thread as answered