diff --git a/internal/twirptest/json_serialization/json_serialization_test.go b/internal/twirptest/json_serialization/json_serialization_test.go index 7d507102..53d51033 100644 --- a/internal/twirptest/json_serialization/json_serialization_test.go +++ b/internal/twirptest/json_serialization/json_serialization_test.go @@ -218,7 +218,7 @@ func TestJSONSerializationCamelCase(t *testing.T) { s := httptest.NewServer( NewJSONSerializationServer( &JSONSerializationService{}, - twirp.WithServerJSONCamelCaseNames(), + twirp.WithServerJSONCamelCaseNames(true), ), ) defer s.Close() diff --git a/server_options.go b/server_options.go index 215b726b..8bb7da1b 100644 --- a/server_options.go +++ b/server_options.go @@ -179,9 +179,13 @@ func WithServerJSONSkipDefaults(skipDefaults bool) ServerOption { } // WithServerJSONCamelCaseNames configures JSON serialization to use -// lowerCamelCase field names rather than proto snake_case names. -func WithServerJSONCamelCaseNames() ServerOption { +// lowerCameCase field names rather than the original proto field names. +// It is disabled by default, because JSON is commonly used for manual +// debugging. But sometimes converting to lowerCamelCase is needed +// to match the default canonical encoding on other proto-json parsers. +// See: https://developers.google.com/protocol-buffers/docs/proto3#json +func WithServerJSONCamelCaseNames(val bool) ServerOption { return func(o *ServerOptions) { - o.JSONCamelCaseNames = true + o.JSONCamelCaseNames = val } } diff --git a/server_options_test.go b/server_options_test.go index 0dd5234f..6c9afa94 100644 --- a/server_options_test.go +++ b/server_options_test.go @@ -125,7 +125,7 @@ func TestWithJSONSkipDefaults(t *testing.T) { func TestWithServerJSONCamelCaseNames(t *testing.T) { opts := &ServerOptions{} - WithServerJSONCamelCaseNames()(opts) + WithServerJSONCamelCaseNames(true)(opts) if !opts.JSONCamelCaseNames { t.Errorf("opts.JSONCamelCaseNames expected to be true, but it is false") }