diff --git a/storage/entity.go b/storage/entity.go index 493dce314d6b..5af9b1ef3e35 100644 --- a/storage/entity.go +++ b/storage/entity.go @@ -16,6 +16,7 @@ package storage import ( "bytes" + "encoding/base64" "encoding/json" "errors" "fmt" @@ -246,7 +247,7 @@ func (e *Entity) MarshalJSON() ([]byte, error) { switch t := v.(type) { case []byte: completeMap[typeKey] = OdataBinary - completeMap[k] = string(t) + completeMap[k] = t case time.Time: completeMap[typeKey] = OdataDateTime completeMap[k] = t.Format(time.RFC3339Nano) @@ -320,7 +321,10 @@ func (e *Entity) UnmarshalJSON(data []byte) error { } switch v { case OdataBinary: - props[valueKey] = []byte(str) + props[valueKey], err = base64.StdEncoding.DecodeString(str) + if err != nil { + return fmt.Errorf(errorTemplate, err) + } case OdataDateTime: t, err := time.Parse("2006-01-02T15:04:05Z", str) if err != nil { diff --git a/storage/entity_test.go b/storage/entity_test.go index 03b0bb4506fc..26e1fd3119fa 100644 --- a/storage/entity_test.go +++ b/storage/entity_test.go @@ -458,7 +458,7 @@ func (s *StorageEntitySuite) TestExecuteQueryNextResults(c *chk.C) { } func (s *StorageEntitySuite) Test_entityMarshalJSON(c *chk.C) { - expected := `{"Address":"Mountain View","Age":23,"AmountDue":200.23,"Binary":"abcd","Binary@odata.type":"Edm.Binary","CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833","CustomerCode@odata.type":"Edm.Guid","CustomerSince":"1992-12-20T21:55:00Z","CustomerSince@odata.type":"Edm.DateTime","IsActive":true,"NumberOfOrders":"255","NumberOfOrders@odata.type":"Edm.Int64","PartitionKey":"mypartitionkey","RowKey":"myrowkey"}` + expected := `{"Address":"Mountain View","Age":23,"AmountDue":200.23,"Binary":"YWJjZA==","Binary@odata.type":"Edm.Binary","CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833","CustomerCode@odata.type":"Edm.Guid","CustomerSince":"1992-12-20T21:55:00Z","CustomerSince@odata.type":"Edm.DateTime","IsActive":true,"NumberOfOrders":"255","NumberOfOrders@odata.type":"Edm.Int64","PartitionKey":"mypartitionkey","RowKey":"myrowkey"}` entity := Entity{ PartitionKey: "mypartitionkey", @@ -504,7 +504,7 @@ func (s *StorageEntitySuite) Test_entityUnmarshalJSON(c *chk.C) { "Age": 23, "AmountDue":200.23, "Binary@odata.type": "Edm.Binary", - "Binary": "abcd", + "Binary": "YWJjZA==", "CustomerCode@odata.type":"Edm.Guid", "CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833", "CustomerSince@odata.type":"Edm.DateTime",