File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -4648,3 +4648,28 @@ func TestUnmarshaler_MapType(t *testing.T) {
46484648 t .Errorf ("expected key:bob=100, got %d" , result .Scores ["key:bob" ])
46494649 }
46504650}
4651+
4652+ func TestUnmarshaler_StructToMap (t * testing.T ) {
4653+ t .Parallel ()
4654+
4655+ // Input is a struct that implements Unmarshaler
4656+ // Output is a map - Unmarshaler should NOT be involved
4657+ input := PersonWithUnmarshaler {
4658+ Name : "Alice" ,
4659+ Age : 30 ,
4660+ }
4661+
4662+ var result map [string ]any
4663+ err := Decode (input , & result )
4664+ if err != nil {
4665+ t .Fatalf ("unexpected error: %s" , err )
4666+ }
4667+
4668+ // Should use normal struct-to-map decoding
4669+ if result ["Name" ] != "Alice" {
4670+ t .Errorf ("expected Name 'Alice', got %v" , result ["Name" ])
4671+ }
4672+ if result ["Age" ] != 30 {
4673+ t .Errorf ("expected Age 30, got %v" , result ["Age" ])
4674+ }
4675+ }
You can’t perform that action at this time.
0 commit comments