uranusjr commented on code in PR #77092:
URL: https://github.com/apache/airflow/pull/77092#discussion_r4688361235


##########
go-sdk/pkg/execution/client.go:
##########
@@ -521,95 +522,32 @@ func resolveExpiry(retention *time.Duration, now 
time.Time) (*genmodels.Time, er
        }
 }
 
-// validateJSONRepresentable checks what the frame encoder actually emits, not
-// the Go value: a reflection walk has to mirror the encoder's field rules 
(tags,
-// "-", omitempty, embedding, marshalers) and misjudges values wherever it 
drifts.
-// On success it returns the encoded bytes, so the caller sends them instead of
-// encoding the value a second time, and whether the value encodes to null.
-func validateJSONRepresentable(value any) (msgpack.RawMessage, bool, error) {
-       var buf bytes.Buffer
-       if err := newFrameEncoder(&buf).Encode(value); err != nil {
-               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
-       }
-       encoded := msgpack.RawMessage(buf.Bytes())
-       // Decoded from its own reader so encoded keeps the whole payload.
-       dec := msgpack.NewDecoder(bytes.NewReader(encoded))
-       dec.SetMapDecoder(decodeStringKeyedMap)
-       decoded, err := dec.DecodeInterface()
+// encodeJSONValue returns the msgpack form of value as encoding/json writes 
it,
+// and whether that is null. The value must take encoding/json's shape, not 
only
+// its field names: argument binding and UnmarshalJSONValue decode it with
+// encoding/json, and a ",string" field or an UnmarshalJSON method rejects a
+// value that was written any other way.
+func encodeJSONValue(value any) (encoded msgpack.RawMessage, isNull bool, err 
error) {
+       blob, err := json.Marshal(value)
        if err != nil {
                return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       if err := validateDecodedValue(decoded); err != nil {
-               return nil, false, err
-       }
-       return encoded, decoded == nil, nil
-}
-
-// decodeStringKeyedMap replaces msgpack's default map decoder, which panics on
-// a uuid.UUID key.
-func decodeStringKeyedMap(d *msgpack.Decoder) (any, error) {
-       n, err := d.DecodeMapLen()
-       if err != nil || n == -1 {
-               return nil, err
-       }
-       m := make(map[string]any, n)
-       for range n {
-               k, err := d.DecodeInterface()
-               if err != nil {
-                       return nil, err
-               }
-               key, ok := k.(string)
-               if !ok {
-                       return nil, fmt.Errorf("map keys must be strings, got 
%T", k)
-               }
-               if m[key], err = d.DecodeInterface(); err != nil {
-                       return nil, err
-               }
+       dec := json.NewDecoder(bytes.NewReader(blob))
+       dec.UseNumber()
+       var decoded any
+       if err := dec.Decode(&decoded); err != nil {
+               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       return m, nil
-}
-
-func validateDecodedValue(v any) error {
-       switch v := v.(type) {
-       case nil, string, bool,
-               int, int8, int16, int32, int64,
-               uint, uint8, uint16, uint32, uint64:
-               return nil
-       case float32:
-               return checkFinite(float64(v))
-       case float64:
-               return checkFinite(v)
-       case time.Time:
-               return fmt.Errorf(
-                       "time.Time is not JSON representable; store 
value.Format(time.RFC3339) " +
-                               "and parse it back with time.Parse",
-               )
-       case []byte:
-               return fmt.Errorf(
-                       "[]byte is not JSON representable; encode it, for 
example with base64.StdEncoding.EncodeToString",
-               )
-       case []any:
-               for _, elem := range v {
-                       if err := validateDecodedValue(elem); err != nil {
-                               return err
-                       }
-               }
-               return nil
-       case map[string]any:
-               for _, elem := range v {
-                       if err := validateDecodedValue(elem); err != nil {
-                               return err
-                       }
-               }
-               return nil
-       default:
-               return fmt.Errorf("%T is not JSON representable", v)
+       if decoded, err = jsonvalue.ResolveNumbers(decoded, "value"); err != 
nil {

Review Comment:
   This turns every whole `float64` into an `int64` for all callers, not only 
the ones this PR targets. A Python downstream task that receives `5` instead of 
`5.0` behaves differently, for example `isinstance(x, float)` or division 
semantics in templated code. Can we preserve floats here? One option is to 
encode the original value with msgpack as before and use the JSON pass only 
when the value's type tree contains a `json.Marshaler`, 
`encoding.TextMarshaler`, or `,string` field. If the lossy behavior is 
accepted, it should be called out more prominently, especially since it affects 
downstreams, not just the current Go task.



##########
go-sdk/pkg/execution/client.go:
##########
@@ -521,95 +522,32 @@ func resolveExpiry(retention *time.Duration, now 
time.Time) (*genmodels.Time, er
        }
 }
 
-// validateJSONRepresentable checks what the frame encoder actually emits, not
-// the Go value: a reflection walk has to mirror the encoder's field rules 
(tags,
-// "-", omitempty, embedding, marshalers) and misjudges values wherever it 
drifts.
-// On success it returns the encoded bytes, so the caller sends them instead of
-// encoding the value a second time, and whether the value encodes to null.
-func validateJSONRepresentable(value any) (msgpack.RawMessage, bool, error) {
-       var buf bytes.Buffer
-       if err := newFrameEncoder(&buf).Encode(value); err != nil {
-               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
-       }
-       encoded := msgpack.RawMessage(buf.Bytes())
-       // Decoded from its own reader so encoded keeps the whole payload.
-       dec := msgpack.NewDecoder(bytes.NewReader(encoded))
-       dec.SetMapDecoder(decodeStringKeyedMap)
-       decoded, err := dec.DecodeInterface()
+// encodeJSONValue returns the msgpack form of value as encoding/json writes 
it,
+// and whether that is null. The value must take encoding/json's shape, not 
only
+// its field names: argument binding and UnmarshalJSONValue decode it with
+// encoding/json, and a ",string" field or an UnmarshalJSON method rejects a
+// value that was written any other way.
+func encodeJSONValue(value any) (encoded msgpack.RawMessage, isNull bool, err 
error) {
+       blob, err := json.Marshal(value)
        if err != nil {
                return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       if err := validateDecodedValue(decoded); err != nil {
-               return nil, false, err
-       }
-       return encoded, decoded == nil, nil
-}
-
-// decodeStringKeyedMap replaces msgpack's default map decoder, which panics on
-// a uuid.UUID key.
-func decodeStringKeyedMap(d *msgpack.Decoder) (any, error) {
-       n, err := d.DecodeMapLen()
-       if err != nil || n == -1 {
-               return nil, err
-       }
-       m := make(map[string]any, n)
-       for range n {
-               k, err := d.DecodeInterface()
-               if err != nil {
-                       return nil, err
-               }
-               key, ok := k.(string)
-               if !ok {
-                       return nil, fmt.Errorf("map keys must be strings, got 
%T", k)
-               }
-               if m[key], err = d.DecodeInterface(); err != nil {
-                       return nil, err
-               }
+       dec := json.NewDecoder(bytes.NewReader(blob))
+       dec.UseNumber()
+       var decoded any
+       if err := dec.Decode(&decoded); err != nil {
+               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       return m, nil
-}
-
-func validateDecodedValue(v any) error {
-       switch v := v.(type) {
-       case nil, string, bool,
-               int, int8, int16, int32, int64,
-               uint, uint8, uint16, uint32, uint64:
-               return nil
-       case float32:
-               return checkFinite(float64(v))
-       case float64:
-               return checkFinite(v)
-       case time.Time:
-               return fmt.Errorf(
-                       "time.Time is not JSON representable; store 
value.Format(time.RFC3339) " +
-                               "and parse it back with time.Parse",
-               )
-       case []byte:
-               return fmt.Errorf(
-                       "[]byte is not JSON representable; encode it, for 
example with base64.StdEncoding.EncodeToString",
-               )
-       case []any:
-               for _, elem := range v {
-                       if err := validateDecodedValue(elem); err != nil {
-                               return err
-                       }
-               }
-               return nil
-       case map[string]any:
-               for _, elem := range v {
-                       if err := validateDecodedValue(elem); err != nil {
-                               return err
-                       }
-               }
-               return nil
-       default:
-               return fmt.Errorf("%T is not JSON representable", v)
+       if decoded, err = jsonvalue.ResolveNumbers(decoded, "value"); err != 
nil {
+               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-}
-
-func checkFinite(f float64) error {
-       if math.IsNaN(f) || math.IsInf(f, 0) {
-               return fmt.Errorf("value must be a finite number; NaN and Inf 
are not JSON representable")
+       var buf bytes.Buffer
+       enc := newFrameEncoder(&buf)
+       // The task state store keeps the value as text, so an unsorted Go map 
would
+       // store the same value with its keys in a different order on each 
write.

Review Comment:
   This function also encodes XCom values, so the comment is misleading.



##########
go-sdk/pkg/execution/client.go:
##########
@@ -521,95 +522,32 @@ func resolveExpiry(retention *time.Duration, now 
time.Time) (*genmodels.Time, er
        }
 }
 
-// validateJSONRepresentable checks what the frame encoder actually emits, not
-// the Go value: a reflection walk has to mirror the encoder's field rules 
(tags,
-// "-", omitempty, embedding, marshalers) and misjudges values wherever it 
drifts.
-// On success it returns the encoded bytes, so the caller sends them instead of
-// encoding the value a second time, and whether the value encodes to null.
-func validateJSONRepresentable(value any) (msgpack.RawMessage, bool, error) {
-       var buf bytes.Buffer
-       if err := newFrameEncoder(&buf).Encode(value); err != nil {
-               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
-       }
-       encoded := msgpack.RawMessage(buf.Bytes())
-       // Decoded from its own reader so encoded keeps the whole payload.
-       dec := msgpack.NewDecoder(bytes.NewReader(encoded))
-       dec.SetMapDecoder(decodeStringKeyedMap)
-       decoded, err := dec.DecodeInterface()
+// encodeJSONValue returns the msgpack form of value as encoding/json writes 
it,
+// and whether that is null. The value must take encoding/json's shape, not 
only
+// its field names: argument binding and UnmarshalJSONValue decode it with
+// encoding/json, and a ",string" field or an UnmarshalJSON method rejects a
+// value that was written any other way.
+func encodeJSONValue(value any) (encoded msgpack.RawMessage, isNull bool, err 
error) {
+       blob, err := json.Marshal(value)
        if err != nil {
                return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       if err := validateDecodedValue(decoded); err != nil {
-               return nil, false, err
-       }
-       return encoded, decoded == nil, nil
-}
-
-// decodeStringKeyedMap replaces msgpack's default map decoder, which panics on
-// a uuid.UUID key.
-func decodeStringKeyedMap(d *msgpack.Decoder) (any, error) {
-       n, err := d.DecodeMapLen()
-       if err != nil || n == -1 {
-               return nil, err
-       }
-       m := make(map[string]any, n)
-       for range n {
-               k, err := d.DecodeInterface()
-               if err != nil {
-                       return nil, err
-               }
-               key, ok := k.(string)
-               if !ok {
-                       return nil, fmt.Errorf("map keys must be strings, got 
%T", k)
-               }
-               if m[key], err = d.DecodeInterface(); err != nil {
-                       return nil, err
-               }
+       dec := json.NewDecoder(bytes.NewReader(blob))
+       dec.UseNumber()
+       var decoded any
+       if err := dec.Decode(&decoded); err != nil {
+               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)

Review Comment:
   This can't fail for a value that `json.Marshal` just produced.



##########
go-sdk/pkg/execution/frames.go:
##########
@@ -76,7 +76,8 @@ func encodeRequest(id int64, body any) ([]byte, error) {
 }
 
 // newFrameEncoder builds the encoder every outbound frame is written with.
-// Use JSON field names for user values; explicit msgpack tags still win.
+// A field without a msgpack tag takes its name from its json tag. XCom
+// and task state values do not reach it as structs: see encodeJSONValue.

Review Comment:
   This does not describe the function itself, but one caller from inside a 
shared helper, and can easily go stale.



##########
go-sdk/pkg/execution/client_test.go:
##########
@@ -473,6 +475,150 @@ func TestCoordinatorClientPushXComAllowsNil(t *testing.T) 
{
        }
 }
 
+type roundTripStatus int
+
+func (roundTripStatus) MarshalJSON() ([]byte, error) {
+       return json.Marshal("ok")
+}
+
+func (s *roundTripStatus) UnmarshalJSON(b []byte) error {
+       var name string
+       if err := json.Unmarshal(b, &name); err != nil {
+               return err
+       }
+       if name != "ok" {
+               return fmt.Errorf("unknown status %q", name)
+       }
+       *s = 0
+       return nil
+}
+
+type roundTripStringID struct {
+       ID int64 `json:"id,string"`
+}
+
+type roundTripMarshaler struct {
+       Status roundTripStatus `json:"status"`
+}
+
+// A value a task returns must decode into the same Go type in a downstream
+// task. Argument binding decodes with encoding/json, so the pushed value has 
to
+// follow encoding/json's rules, not only its field names.
+func TestCoordinatorClientPushXComRoundTripsThroughBinding(t *testing.T) {
+       tests := []struct {
+               name  string
+               value any
+       }{
+               {name: "json string option", value: roundTripStringID{ID: 123}},
+               {name: "json marshaler", value: roundTripMarshaler{Status: 0}},
+               {name: "datetime", value: time.Date(2026, 5, 15, 0, 0, 0, 0, 
time.UTC)},
+               {name: "uuid", value: uuid.MustParse(testTIID)},
+               {name: "byte slice", value: []byte("raw")},
+               {name: "uuid map key", value: 
map[uuid.UUID]string{uuid.MustParse(testTIID): "a"}},
+               {name: "integer past 2^53", value: int64(1<<53 + 1)},
+       }
+
+       for _, tc := range tests {
+               t.Run(tc.name, func(t *testing.T) {
+                       responsePayload := encodeResponseFrame(t, 0, 
map[string]any{"type": "OKResponse"}, nil)
+                       var responseBuf bytes.Buffer
+                       require.NoError(t, writeFrame(&responseBuf, 
responsePayload))
+
+                       var requestBuf bytes.Buffer
+                       logger := slog.New(slog.NewTextHandler(io.Discard, nil))
+                       client := NewCoordinatorClient(
+                               NewCoordinatorComm(&responseBuf, &requestBuf, 
logger), testTIID,
+                       )
+                       ti := sdk.TaskInstance{DagID: "d", RunID: "r", TaskID: 
"t"}
+
+                       require.NoError(t, 
client.PushXCom(context.Background(), ti, "return_value", tc.value))
+
+                       sent, err := readFrame(&requestBuf)
+                       require.NoError(t, err)
+                       pushed := rawToMap(t, sent.Body)["value"]
+
+                       got, err := binding.DecodeLiteral(pushed, 
reflect.TypeOf(tc.value))
+
+                       require.NoError(t, err)
+                       assert.Equal(t, tc.value, got.Interface())
+               })
+       }
+}
+
+// JSON text does not say whether a number was a float, so a float64 with no
+// fractional part is read back as an integer.
+func TestEncodeJSONValueStoresWholeFloatAsInteger(t *testing.T) {

Review Comment:
   This one too.



##########
go-sdk/pkg/execution/client_test.go:
##########
@@ -624,32 +770,14 @@ func TestTaskStateStoreSetRejectsMisconfiguredRetention(t 
*testing.T) {
        assert.Zero(t, requestBuf.Len(), "a rejected write must not reach the 
supervisor")
 }
 
-// Mirrors Python's test_set_datetime_raises_validation_error.

Review Comment:
   Accidentally deleted?



##########
go-sdk/pkg/execution/client_test.go:
##########
@@ -473,6 +475,150 @@ func TestCoordinatorClientPushXComAllowsNil(t *testing.T) 
{
        }
 }
 
+type roundTripStatus int
+
+func (roundTripStatus) MarshalJSON() ([]byte, error) {
+       return json.Marshal("ok")
+}
+
+func (s *roundTripStatus) UnmarshalJSON(b []byte) error {
+       var name string
+       if err := json.Unmarshal(b, &name); err != nil {
+               return err
+       }
+       if name != "ok" {
+               return fmt.Errorf("unknown status %q", name)
+       }
+       *s = 0
+       return nil
+}
+
+type roundTripStringID struct {
+       ID int64 `json:"id,string"`
+}
+
+type roundTripMarshaler struct {
+       Status roundTripStatus `json:"status"`
+}
+
+// A value a task returns must decode into the same Go type in a downstream
+// task. Argument binding decodes with encoding/json, so the pushed value has 
to
+// follow encoding/json's rules, not only its field names.

Review Comment:
   On the other hand, this long message explains little more than the test 
function’s name itself.



##########
go-sdk/pkg/execution/client.go:
##########
@@ -521,95 +522,32 @@ func resolveExpiry(retention *time.Duration, now 
time.Time) (*genmodels.Time, er
        }
 }
 
-// validateJSONRepresentable checks what the frame encoder actually emits, not
-// the Go value: a reflection walk has to mirror the encoder's field rules 
(tags,
-// "-", omitempty, embedding, marshalers) and misjudges values wherever it 
drifts.
-// On success it returns the encoded bytes, so the caller sends them instead of
-// encoding the value a second time, and whether the value encodes to null.
-func validateJSONRepresentable(value any) (msgpack.RawMessage, bool, error) {
-       var buf bytes.Buffer
-       if err := newFrameEncoder(&buf).Encode(value); err != nil {
-               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
-       }
-       encoded := msgpack.RawMessage(buf.Bytes())
-       // Decoded from its own reader so encoded keeps the whole payload.
-       dec := msgpack.NewDecoder(bytes.NewReader(encoded))
-       dec.SetMapDecoder(decodeStringKeyedMap)
-       decoded, err := dec.DecodeInterface()
+// encodeJSONValue returns the msgpack form of value as encoding/json writes 
it,
+// and whether that is null. The value must take encoding/json's shape, not 
only
+// its field names: argument binding and UnmarshalJSONValue decode it with
+// encoding/json, and a ",string" field or an UnmarshalJSON method rejects a
+// value that was written any other way.
+func encodeJSONValue(value any) (encoded msgpack.RawMessage, isNull bool, err 
error) {
+       blob, err := json.Marshal(value)
        if err != nil {
                return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       if err := validateDecodedValue(decoded); err != nil {
-               return nil, false, err
-       }
-       return encoded, decoded == nil, nil
-}
-
-// decodeStringKeyedMap replaces msgpack's default map decoder, which panics on
-// a uuid.UUID key.
-func decodeStringKeyedMap(d *msgpack.Decoder) (any, error) {
-       n, err := d.DecodeMapLen()
-       if err != nil || n == -1 {
-               return nil, err
-       }
-       m := make(map[string]any, n)
-       for range n {
-               k, err := d.DecodeInterface()
-               if err != nil {
-                       return nil, err
-               }
-               key, ok := k.(string)
-               if !ok {
-                       return nil, fmt.Errorf("map keys must be strings, got 
%T", k)
-               }
-               if m[key], err = d.DecodeInterface(); err != nil {
-                       return nil, err
-               }
+       dec := json.NewDecoder(bytes.NewReader(blob))
+       dec.UseNumber()
+       var decoded any
+       if err := dec.Decode(&decoded); err != nil {
+               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       return m, nil
-}
-
-func validateDecodedValue(v any) error {
-       switch v := v.(type) {
-       case nil, string, bool,
-               int, int8, int16, int32, int64,
-               uint, uint8, uint16, uint32, uint64:
-               return nil
-       case float32:
-               return checkFinite(float64(v))
-       case float64:
-               return checkFinite(v)
-       case time.Time:
-               return fmt.Errorf(
-                       "time.Time is not JSON representable; store 
value.Format(time.RFC3339) " +
-                               "and parse it back with time.Parse",
-               )
-       case []byte:
-               return fmt.Errorf(
-                       "[]byte is not JSON representable; encode it, for 
example with base64.StdEncoding.EncodeToString",
-               )
-       case []any:
-               for _, elem := range v {
-                       if err := validateDecodedValue(elem); err != nil {
-                               return err
-                       }
-               }
-               return nil
-       case map[string]any:
-               for _, elem := range v {
-                       if err := validateDecodedValue(elem); err != nil {
-                               return err
-                       }
-               }
-               return nil
-       default:
-               return fmt.Errorf("%T is not JSON representable", v)
+       if decoded, err = jsonvalue.ResolveNumbers(decoded, "value"); err != 
nil {

Review Comment:
   Also (this applies more to the entire block), every push now goes through 
three passes. #75601 posted numbers for its single extra pass; this should do 
the same.



##########
go-sdk/sdk/sdk.go:
##########
@@ -127,9 +127,14 @@ type XComClient interface {
 
        // PushXCom stores value under key for the given task instance ti.
        //
-       // value must be JSON serializable; nil is allowed and is pushed as 
null.
-       // A time.Time, a byte slice or array such as a uuid.UUID, or a 
non-finite
-       // float is rejected before it is sent.
+       // value is stored as encoding/json writes it, so json struct tags and
+       // MarshalJSON methods apply: a time.Time is stored as an RFC 3339 
string
+       // and a byte slice as a base64 string, which GetXCom returns as a 
string.
+       // A float64 with no fractional part, such as 5.0, is stored as the 
integer
+       // 5. nil is allowed and is pushed as null. A value that json.Marshal
+       // rejects, such as a non-finite float, is rejected before it is sent, 
and
+       // so is an integer that fits in neither int64 nor uint64, or a number 
past
+       // the range of a float64.

Review Comment:
   The godoc now has encoding edge cases repeated in multiple places. There 
should only be one copy.



##########
go-sdk/pkg/execution/client.go:
##########
@@ -521,95 +522,32 @@ func resolveExpiry(retention *time.Duration, now 
time.Time) (*genmodels.Time, er
        }
 }
 
-// validateJSONRepresentable checks what the frame encoder actually emits, not
-// the Go value: a reflection walk has to mirror the encoder's field rules 
(tags,
-// "-", omitempty, embedding, marshalers) and misjudges values wherever it 
drifts.
-// On success it returns the encoded bytes, so the caller sends them instead of
-// encoding the value a second time, and whether the value encodes to null.
-func validateJSONRepresentable(value any) (msgpack.RawMessage, bool, error) {
-       var buf bytes.Buffer
-       if err := newFrameEncoder(&buf).Encode(value); err != nil {
-               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
-       }
-       encoded := msgpack.RawMessage(buf.Bytes())
-       // Decoded from its own reader so encoded keeps the whole payload.
-       dec := msgpack.NewDecoder(bytes.NewReader(encoded))
-       dec.SetMapDecoder(decodeStringKeyedMap)
-       decoded, err := dec.DecodeInterface()
+// encodeJSONValue returns the msgpack form of value as encoding/json writes 
it,
+// and whether that is null. The value must take encoding/json's shape, not 
only
+// its field names: argument binding and UnmarshalJSONValue decode it with
+// encoding/json, and a ",string" field or an UnmarshalJSON method rejects a
+// value that was written any other way.
+func encodeJSONValue(value any) (encoded msgpack.RawMessage, isNull bool, err 
error) {
+       blob, err := json.Marshal(value)
        if err != nil {
                return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       if err := validateDecodedValue(decoded); err != nil {
-               return nil, false, err
-       }
-       return encoded, decoded == nil, nil
-}
-
-// decodeStringKeyedMap replaces msgpack's default map decoder, which panics on
-// a uuid.UUID key.
-func decodeStringKeyedMap(d *msgpack.Decoder) (any, error) {
-       n, err := d.DecodeMapLen()
-       if err != nil || n == -1 {
-               return nil, err
-       }
-       m := make(map[string]any, n)
-       for range n {
-               k, err := d.DecodeInterface()
-               if err != nil {
-                       return nil, err
-               }
-               key, ok := k.(string)
-               if !ok {
-                       return nil, fmt.Errorf("map keys must be strings, got 
%T", k)
-               }
-               if m[key], err = d.DecodeInterface(); err != nil {
-                       return nil, err
-               }
+       dec := json.NewDecoder(bytes.NewReader(blob))
+       dec.UseNumber()
+       var decoded any
+       if err := dec.Decode(&decoded); err != nil {
+               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-       return m, nil
-}
-
-func validateDecodedValue(v any) error {
-       switch v := v.(type) {
-       case nil, string, bool,
-               int, int8, int16, int32, int64,
-               uint, uint8, uint16, uint32, uint64:
-               return nil
-       case float32:
-               return checkFinite(float64(v))
-       case float64:
-               return checkFinite(v)
-       case time.Time:
-               return fmt.Errorf(
-                       "time.Time is not JSON representable; store 
value.Format(time.RFC3339) " +
-                               "and parse it back with time.Parse",
-               )
-       case []byte:
-               return fmt.Errorf(
-                       "[]byte is not JSON representable; encode it, for 
example with base64.StdEncoding.EncodeToString",
-               )
-       case []any:
-               for _, elem := range v {
-                       if err := validateDecodedValue(elem); err != nil {
-                               return err
-                       }
-               }
-               return nil
-       case map[string]any:
-               for _, elem := range v {
-                       if err := validateDecodedValue(elem); err != nil {
-                               return err
-                       }
-               }
-               return nil
-       default:
-               return fmt.Errorf("%T is not JSON representable", v)
+       if decoded, err = jsonvalue.ResolveNumbers(decoded, "value"); err != 
nil {
+               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)
        }
-}
-
-func checkFinite(f float64) error {
-       if math.IsNaN(f) || math.IsInf(f, 0) {
-               return fmt.Errorf("value must be a finite number; NaN and Inf 
are not JSON representable")
+       var buf bytes.Buffer
+       enc := newFrameEncoder(&buf)
+       // The task state store keeps the value as text, so an unsorted Go map 
would
+       // store the same value with its keys in a different order on each 
write.
+       enc.SetSortMapKeys(true)
+       if err := enc.Encode(decoded); err != nil {
+               return nil, false, fmt.Errorf("%T is not JSON representable: 
%w", value, err)

Review Comment:
   This also can’t fail. I understand they probably exists since Go kind of 
forces you to add them, but if these are ever reached, we have big problems, so 
the error message should probably suggest such.



-- 
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]

Reply via email to