Fix camel case JSON tags

This commit is contained in:
pavel 2026-08-27 16:57:12 +02:00
commit b0a52de4ea
2 changed files with 9 additions and 4 deletions

View file

@ -30,7 +30,7 @@ func TestGenerateGoDataClassJSONNamingOverride(t *testing.T) {
package demo
@jsonNaming(camelCase)
data class Account(var availableBalance: Double)
data class Account(var availableBalance: Double, var Type: String)
`)
if err != nil {
t.Fatalf("parse failed: %v", err)
@ -39,8 +39,10 @@ data class Account(var availableBalance: Double)
if err != nil {
t.Fatalf("generation failed: %v", err)
}
if !strings.Contains(string(out), "`json:\"availableBalance\"`") {
t.Fatalf("generated Go missing camelCase tag:\n%s", out)
for _, want := range []string{"`json:\"availableBalance\"`", "`json:\"type\"`"} {
if !strings.Contains(string(out), want) {
t.Fatalf("generated Go missing camelCase tag %q:\n%s", want, out)
}
}
}

View file

@ -1960,7 +1960,10 @@ func jsonFieldName(name, policy string) string {
case "", "snakeCase":
return snakeCase(name)
case "camelCase":
return name
if name == "" {
return name
}
return strings.ToLower(name[:1]) + name[1:]
case "pascalCase":
return exportedGoName(name)
case "kebabCase":