2
0

Fix JSON encoding for pointer to structs implementing json.Marshaler

https://github.com/jackc/pgx/issues/1681
This commit is contained in:
Jack Christensen
2023-07-11 20:28:36 -05:00
parent 507a9e9ad3
commit 524f661136
3 changed files with 41 additions and 0 deletions
+7
View File
@@ -25,6 +25,13 @@ func (c JSONCodec) PlanEncode(m *Map, oid uint32, format int16, value any) Encod
case []byte:
return encodePlanJSONCodecEitherFormatByteSlice{}
// Must come before trying wrap encode plans because a pointer to a struct may be unwrapped to a struct that can be
// marshalled.
//
// https://github.com/jackc/pgx/issues/1681
case json.Marshaler:
return encodePlanJSONCodecEitherFormatMarshal{}
// Cannot rely on driver.Valuer being handled later because anything can be marshalled.
//
// https://github.com/jackc/pgx/issues/1430