@@ -65,7 +65,7 @@ func ValueSchemaCodec[V any](cdc ValueCodec[V]) (SchemaCodec[V], error) {
65
65
66
66
// FallbackSchemaCodec returns a fallback schema codec for T when one isn't explicitly
67
67
// specified with HasSchemaCodec. It maps all simple types directly to schema kinds
68
- // and converts everything else to JSON.
68
+ // and converts everything else to JSON String .
69
69
func FallbackSchemaCodec [T any ]() SchemaCodec [T ] {
70
70
var t T
71
71
kind := schema .KindForGoValue (t )
@@ -81,20 +81,20 @@ func FallbackSchemaCodec[T any]() SchemaCodec[T] {
81
81
FromSchemaType : nil ,
82
82
}
83
83
} else {
84
- // we default to encoding everything to JSON
84
+ // we default to encoding everything to JSON String
85
85
return SchemaCodec [T ]{
86
- Fields : []schema.Field {{Kind : schema .JSONKind }},
86
+ Fields : []schema.Field {{Kind : schema .StringKind }},
87
87
ToSchemaType : func (t T ) (any , error ) {
88
88
bz , err := json .Marshal (t )
89
- return json .RawMessage (bz ), err
89
+ return string ( json .RawMessage (bz ) ), err
90
90
},
91
91
FromSchemaType : func (a any ) (T , error ) {
92
92
var t T
93
- bz , ok := a .(json. RawMessage )
93
+ sz , ok := a .(string )
94
94
if ! ok {
95
- return t , fmt .Errorf ("expected json.RawMessage , got %T" , a )
95
+ return t , fmt .Errorf ("expected string , got %T" , a )
96
96
}
97
- err := json .Unmarshal (bz , & t )
97
+ err := json .Unmarshal ([] byte ( sz ) , & t )
98
98
return t , err
99
99
},
100
100
}
0 commit comments