@@ -1387,3 +1387,54 @@ func TestUnmarshalNestedStructSlice(t *testing.T) {
1387
1387
out .Teams [0 ].Members [0 ].Firstname )
1388
1388
}
1389
1389
}
1390
+
1391
+ type HeaderData struct {
1392
+ ID string `jsonapi:"primary,header-data"`
1393
+ Name string `jsonapi:"attr,name"`
1394
+ Headers map [string ][]string `jsonapi:"attr,headers"`
1395
+ }
1396
+
1397
+ func TestUnmarshalMapStringSlice (t * testing.T ) {
1398
+ headers := map [string ][]string {
1399
+ "cache-control" : {"private" },
1400
+ "content-length" : {"129" },
1401
+ }
1402
+ sample := map [string ]interface {}{
1403
+ "data" : map [string ]interface {}{
1404
+ "type" : "header-data" ,
1405
+ "id" : "123" ,
1406
+ "attributes" : map [string ]interface {}{
1407
+ "name" : "Planet Express" ,
1408
+ "headers" : headers ,
1409
+ },
1410
+ },
1411
+ }
1412
+
1413
+ data , err := json .Marshal (sample )
1414
+ if err != nil {
1415
+ t .Fatal (err )
1416
+ }
1417
+ in := bytes .NewReader (data )
1418
+ out := new (HeaderData )
1419
+
1420
+ if err := UnmarshalPayload (in , out ); err != nil {
1421
+ t .Fatal (err )
1422
+ }
1423
+
1424
+ if len (out .Headers ["cache-control" ]) == 0 {
1425
+ t .Fatalf ("Expected Headers to have Cache Control values, but got:`%s`" , out .Headers ["cache-control" ])
1426
+ }
1427
+
1428
+ if len (out .Headers ["content-length" ]) == 0 {
1429
+ t .Fatalf ("Expected Headers to have Content Length values, but got:`%s`" , out .Headers ["content-length" ])
1430
+ }
1431
+
1432
+ if out .Headers ["cache-control" ][0 ] != "private" {
1433
+ t .Fatalf ("Expected Cache Control Header to have 'private' value, but got:`%s`" , out .Headers ["cache-control" ])
1434
+ }
1435
+
1436
+ if out .Headers ["content-length" ][0 ] != "129" {
1437
+ t .Fatalf ("Expected Content Length Header to have '129' value, but got:`%s`" , out .Headers ["content-length" ])
1438
+ }
1439
+
1440
+ }
0 commit comments