Compare commits

...

6 Commits

Author SHA1 Message Date
Steven Allen
bd441bb43e gx publish 0.7.22 2018-07-12 10:21:27 +02:00
Steven Allen
10a4d040b4 Merge pull request #55 from ipfs/bug/marshal
Use value receiver for MarshalJSON so we can marshal values
2018-07-12 08:19:51 +00:00
Fritz Schneider
d204c18f7a make test a little more clear 2018-07-11 11:24:59 -10:00
Fritz Schneider
b41162260a fix typo 2018-07-11 11:21:16 -10:00
Fritz Schneider
9cb0b7bcae use value receiver 2018-07-11 11:20:53 -10:00
Steven Allen
5b04f30433 gx publish 0.7.21 2018-06-08 20:25:20 -07:00
4 changed files with 34 additions and 5 deletions

View File

@@ -1 +1 @@
0.7.20: QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY
0.7.22: QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP

2
cid.go
View File

@@ -410,7 +410,7 @@ func (c *Cid) UnmarshalJSON(b []byte) error {
//
// Note that this formatting comes from the IPLD specification
// (https://github.com/ipld/specs/tree/master/ipld)
func (c *Cid) MarshalJSON() ([]byte, error) {
func (c Cid) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("{\"/\":\"%s\"}", c.String())), nil
}

View File

@@ -383,3 +383,32 @@ func TestFromJson(t *testing.T) {
t.Fatal("json parsing failed")
}
}
func TestJsonRoundTrip(t *testing.T) {
exp, err := Decode("zb2rhhFAEMepUBbGyP1k8tGfz7BSciKXP6GHuUeUsJBaK6cqG")
if err != nil {
t.Fatal(err)
}
// Verify it works for a *Cid.
enc, err := json.Marshal(exp)
if err != nil {
t.Fatal(err)
}
var actual Cid
err = json.Unmarshal(enc, &actual)
if !exp.Equals(&actual) {
t.Fatal("cids not equal for *Cid")
}
// Verify it works for a Cid.
enc, err = json.Marshal(*exp)
if err != nil {
t.Fatal(err)
}
var actual2 Cid
err = json.Unmarshal(enc, &actual2)
if !exp.Equals(&actual2) {
t.Fatal("cids not equal for Cid")
}
}

View File

@@ -9,9 +9,9 @@
"gxDependencies": [
{
"author": "whyrusleeping",
"hash": "QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua",
"hash": "QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8",
"name": "go-multihash",
"version": "1.0.7"
"version": "1.0.8"
},
{
"author": "whyrusleeping",
@@ -25,6 +25,6 @@
"license": "MIT",
"name": "go-cid",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "0.7.20"
"version": "0.7.22"
}