]> Cypherpunks repositories - gostls13.git/commitdiff
json: expose map in generic representation
authorRuss Cox <rsc@golang.org>
Tue, 24 Nov 2009 02:11:00 +0000 (18:11 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 24 Nov 2009 02:11:00 +0000 (18:11 -0800)
R=r, r1
https://golang.org/cl/157146

src/pkg/json/generic.go
src/pkg/json/generic_test.go

index eed8f9daa260e6a7b92065d3b32b4cf76cee3e5c..0140b50e485bc17f3ae31c05b852949eeb833ab4 100644 (file)
@@ -33,6 +33,7 @@ type Json interface {
        Get(s string) Json;     // field lookup (MapKind)
        Elem(i int) Json;       // element lookup (ArrayKind)
        Len() int;              // length (ArrayKind, MapKind)
+       Map() map[string]Json;  // map form (MapKind)
 }
 
 // JsonToString returns the textual JSON syntax representation
@@ -63,6 +64,7 @@ func (*_Null) Bool() bool             { return false }
 func (*_Null) Get(s string) Json       { return Null }
 func (*_Null) Elem(int) Json           { return Null }
 func (*_Null) Len() int                        { return 0 }
+func (*_Null) Map() map[string]Json    { return nil }
 
 type _String struct {
        s       string;
@@ -158,6 +160,7 @@ func (j *_Map) String() string {
        s += "}";
        return s;
 }
+func (j *_Map) Map() map[string]Json   { return j.m }
 
 // Walk evaluates path relative to the JSON object j.
 // Path is taken as a sequence of slash-separated field names
index 7fc7bcc55a2b3ff664d59820883f5abac82e5eaa..5b660f268f01bdf3dd3c402bcbf4bb6370207248 100644 (file)
@@ -5,6 +5,7 @@
 package json
 
 import (
+       "reflect";
        "testing";
 )
 
@@ -73,4 +74,7 @@ func TestJsonMap(t *testing.T) {
                        t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v)
                }
        }
+       if !reflect.DeepEqual(values, mapv.Map()) {
+               t.Errorf("DeepEqual(values, mapv.Map()) failed")
+       }
 }