Revanth14 commented on code in PR #2361:
URL: https://github.com/apache/iceberg-go/pull/2361#discussion_r4460675482
##########
types.go:
##########
@@ -431,13 +431,28 @@ func (s *StructType) Equals(other Type) bool {
func (s *StructType) Fields() []NestedField { return s.FieldList }
-func (s *StructType) MarshalJSON() ([]byte, error) {
- type Alias StructType
+// The JSON methods of the nested types name every serialized field instead of
+// encoding through an alias of the type, so the wire format does not depend on
+// which Go fields are exported.
+func (s *StructType) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
- Type string `json:"type"`
- *Alias
- }{Type: s.Type(), Alias: (*Alias)(s)})
+ Type string `json:"type"`
+ Fields []NestedField `json:"fields"`
+ }{Type: s.Type(), Fields: s.FieldList})
+}
+
+func (s *StructType) UnmarshalJSON(b []byte) error {
+ aux := struct {
+ Fields []NestedField `json:"fields"`
+ }{}
+ if err := json.Unmarshal(b, &aux); err != nil {
+ return err
+ }
+
+ s.FieldList = aux.Fields
Review Comment:
Yes, intended: `ListType`, `MapType`, `NestedField` and `Schema` all decode
into a fresh value and replace the target, so a struct keeping a stale field
list would be the only exception. `TestStructTypeUnmarshalMissingFieldsIsEmpty`
now decodes into a populated value, and restoring `main`'s behaviour fails it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]