From 2e26c4348e6a9a5599620b1eba68a6b9237098d2 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Thu, 21 Sep 2023 08:41:21 +0930 Subject: [PATCH] lib: fix json_encode for null values The previous code would fail with "internal error: json encode mapping out of sync: type conversion error from 'null_type' to '*int'". Removing the entry from encodableTypes allows the conversion look-up to fall through to the relevant protobuf type. --- lib/types.go | 1 - testdata/json_encode.txt | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/types.go b/lib/types.go index 00eff6d..037dd1d 100644 --- a/lib/types.go +++ b/lib/types.go @@ -52,7 +52,6 @@ var ( types.IntType: reflectInt64Type, types.ListType: reflect.TypeOf([]interface{}(nil)), types.MapType: reflectMapStringAnyType, - types.NullType: reflect.TypeOf((*int)(nil)), // Any pointer will do. types.StringType: reflectStringType, types.TimestampType: reflect.TypeOf(time.Time{}), types.UintType: reflect.TypeOf(uint64(0)), diff --git a/testdata/json_encode.txt b/testdata/json_encode.txt index 5bcf96d..0fea196 100644 --- a/testdata/json_encode.txt +++ b/testdata/json_encode.txt @@ -4,6 +4,7 @@ cmp stdout want.txt -- src.cel -- [ + null.encode_json(), {"a":1, "b":[1, 2, 3]}.encode_json(), encode_json({"a":1, "b":[1, 2, 3]}), ({ @@ -25,6 +26,7 @@ cmp stdout want.txt ] -- want.txt -- [ + "null", "{\"a\":1,\"b\":[1,2,3]}", "{\"a\":1,\"b\":[1,2,3]}", "{\"a\":{\"b\":{\"c\":1}}}",