File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -296,14 +296,31 @@ func MaxAgeMap(maxAge time.Duration, claims Map) {
296296func Merge (values ... any ) ([]byte , error ) {
297297 parts := make ([][]byte , 0 , len (values ))
298298
299- for _ , value := range values {
299+ for i , value := range values {
300300 if value == nil {
301301 continue
302302 }
303- jsonBytes , err := json .Marshal (value )
303+
304+ var (
305+ jsonBytes []byte
306+ err error
307+ )
308+
309+ switch v := value .(type ) {
310+ case string :
311+ // If the value is a string, treat it as a JSON object.
312+ jsonBytes = []byte (v )
313+ case []byte :
314+ // If the value is a byte slice, treat it as a JSON object.
315+ jsonBytes = v
316+ default :
317+ jsonBytes , err = json .Marshal (value )
318+ }
319+
304320 if err != nil {
305- return nil , err
321+ return nil , fmt . Errorf ( "part: %d: %w" , i + 1 , err )
306322 }
323+
307324 // Check that the marshaled JSON is an object.
308325 if len (jsonBytes ) < 2 || jsonBytes [0 ] != '{' || jsonBytes [len (jsonBytes )- 1 ] != '}' {
309326 return nil , fmt .Errorf ("value does not marshal to a JSON object: %v" , value )
You can’t perform that action at this time.
0 commit comments