© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•13mo ago•
3 replies
Core

✅ Serialized enum starts with uppercase / camel case is ignored

Hello,
I am using the newer source generated enum serializer (introduced in .NET 8), but for some reason the serialized string starts with uppercase instead of lowercase. https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation#source-generation-support-in-aspnet-core


[JsonSourceGenerationOptions(UseStringEnumConverter = true, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(RedirectType))]
public partial class EnumToStringJsonContext : JsonSerializerContext;
[JsonSourceGenerationOptions(UseStringEnumConverter = true, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(RedirectType))]
public partial class EnumToStringJsonContext : JsonSerializerContext;


I even tried another configuration, but it had the same outcome

public class CamelCaseEnumConverter<TEnum>() : 
    JsonStringEnumConverter<TEnum>(JsonNamingPolicy.CamelCase) where TEnum : struct, Enum;

[JsonSourceGenerationOptions(
    UseStringEnumConverter = true,
     Converters =
         [
             typeof(CamelCaseEnumConverter<RedirectType>)
         ]),
 JsonSerializable(typeof(RedirectType))
]
public partial class EnumToStringJsonContext : JsonSerializerContext;
public class CamelCaseEnumConverter<TEnum>() : 
    JsonStringEnumConverter<TEnum>(JsonNamingPolicy.CamelCase) where TEnum : struct, Enum;

[JsonSourceGenerationOptions(
    UseStringEnumConverter = true,
     Converters =
         [
             typeof(CamelCaseEnumConverter<RedirectType>)
         ]),
 JsonSerializable(typeof(RedirectType))
]
public partial class EnumToStringJsonContext : JsonSerializerContext;
How to use source generation in System.Text.Json - .NET
Learn how to use source generation in System.Text.Json.
How to use source generation in System.Text.Json - .NET
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ How to specify camel case for all response properties with Newtonsoft
C#CC# / help
16mo ago
Dapper enum to snake_case string
C#CC# / help
3y ago
✅ How to convert controller route name to camel case automatically?
C#CC# / help
11mo ago
How can I make FluentValidation return errors in camel case??
C#CC# / help
15mo ago