@@ -16,6 +16,8 @@ import (
1616 "strings"
1717 "sync"
1818 "unicode/utf8"
19+
20+ "golang.org/x/tools/internal/mcp/internal/util"
1921)
2022
2123// The value of the "$schema" keyword for the version that we can validate.
@@ -688,7 +690,8 @@ func properties(v reflect.Value) iter.Seq2[string, reflect.Value] {
688690 for name , sf := range structPropertiesOf (v .Type ()) {
689691 val := v .FieldByIndex (sf .Index )
690692 if val .IsZero () {
691- if tag , ok := sf .Tag .Lookup ("json" ); ok && (strings .Contains (tag , "omitempty" ) || strings .Contains (tag , "omitzero" )) {
693+ info := util .FieldJSONInfo (sf )
694+ if info .Settings ["omitempty" ] || info .Settings ["omitzero" ] {
692695 continue
693696 }
694697 }
@@ -740,30 +743,11 @@ func structPropertiesOf(t reflect.Type) propertyMap {
740743 }
741744 props := map [string ]reflect.StructField {}
742745 for _ , sf := range reflect .VisibleFields (t ) {
743- if name , ok := jsonName (sf ); ok {
744- props [name ] = sf
746+ info := util .FieldJSONInfo (sf )
747+ if ! info .Omit {
748+ props [info .Name ] = sf
745749 }
746750 }
747751 structProperties .Store (t , props )
748752 return props
749753}
750-
751- // jsonName returns the name for f as would be used by [json.Marshal].
752- // That is the name in the json struct tag, or the field name if there is no tag.
753- // If f is not exported or the tag is "-", jsonName returns "", false.
754- func jsonName (f reflect.StructField ) (string , bool ) {
755- if ! f .IsExported () {
756- return "" , false
757- }
758- if tag , ok := f .Tag .Lookup ("json" ); ok {
759- name , _ , found := strings .Cut (tag , "," )
760- // "-" means omit, but "-," means the name is "-"
761- if name == "-" && ! found {
762- return "" , false
763- }
764- if name != "" {
765- return name , true
766- }
767- }
768- return f .Name , true
769- }
0 commit comments