Skip to content

Commit

Permalink
Fixing JSON Unmarshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Jan 25, 2024
1 parent beb799f commit b09272a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions bill/outlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (o *Outlay) Validate() error {
)
}

// JSONUnmarshal helps migrate the desc field to description.
func (o *Outlay) JSONUnmarshal(data []byte) error {
// UnmarshalJSON helps migrate the desc field to description.
func (o *Outlay) UnmarshalJSON(data []byte) error {
type Alias Outlay
aux := &struct {
Desc string `json:"desc"`
Expand Down
3 changes: 2 additions & 1 deletion bill/outlay_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bill

import (
"encoding/json"
"testing"

"github.com/invopop/gobl/num"
Expand All @@ -10,7 +11,7 @@ import (

func TestOutlayUnmarshal(t *testing.T) {
o := new(Outlay)
err := o.JSONUnmarshal([]byte(`{"desc":"foo"}`))
err := json.Unmarshal([]byte(`{"desc":"foo"}`), o)
require.NoError(t, err)
assert.Equal(t, "foo", o.Description)
}
Expand Down
4 changes: 2 additions & 2 deletions pay/advance.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (a *Advance) CalculateFrom(totalWithTax num.Amount) {
}
}

// JSONUnmarshal helps migrate the desc field to description.
func (a *Advance) JSONUnmarshal(data []byte) error {
// UnmarshalJSON helps migrate the desc field to description.
func (a *Advance) UnmarshalJSON(data []byte) error {
type Alias Advance
aux := &struct {
Desc string `json:"desc,omitempty"`
Expand Down
3 changes: 2 additions & 1 deletion pay/advance_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pay_test

import (
"encoding/json"
"testing"

"github.com/invopop/gobl/pay"
Expand All @@ -10,7 +11,7 @@ import (

func TestAdvanceUnmarshal(t *testing.T) {
a := new(pay.Advance)
err := a.JSONUnmarshal([]byte(`{"desc":"foo"}`))
err := json.Unmarshal([]byte(`{"desc":"foo"}`), a)
require.NoError(t, err)
assert.Equal(t, "foo", a.Description)
}
4 changes: 2 additions & 2 deletions regimes/co/examples/out/simplified.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "2346991aab5ee704bd2b0ad14a06260aaf81fa7baca32c2bcd211cbc177aa6a2"
"val": "f23f62eb0cf68db88a55bd391e5410bfba7bf06c24e1a7a863191346b07b644c"
},
"draft": true
},
Expand Down Expand Up @@ -50,7 +50,7 @@
"payment": {
"advances": [
{
"desc": "Prepaid",
"description": "Prepaid",
"percent": "100%",
"amount": "238000.00"
}
Expand Down
4 changes: 2 additions & 2 deletions regimes/es/examples/out/invoice-es-es-vateqs-provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "72e81bc4530fcd56154953690b56d170d3de5109a833642876e1dc33399f8d6e"
"val": "43f53d3728f1840ae9a652d616a7af90f827a937e375e9bf68d2e5d61c986ddc"
},
"draft": true
},
Expand Down Expand Up @@ -111,7 +111,7 @@
"advances": [
{
"date": "2021-09-01",
"desc": "Deposit paid upfront",
"description": "Deposit paid upfront",
"amount": "25.00"
}
],
Expand Down
6 changes: 3 additions & 3 deletions regimes/mx/examples/out/prepaid-invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"uuid": "8a51fd30-2a27-11ee-be56-0242ac120002",
"dig": {
"alg": "sha256",
"val": "d8defb2c2e8f823f3ee18d3b75516cd38532f735a6f2635ceb7950af3fa7c150"
"val": "e87b2b2acf012c7fa3b9d9eda0046943b173b98ce47fa9bd27144f27b157b1b0"
},
"draft": true
},
Expand Down Expand Up @@ -94,13 +94,13 @@
"advances": [
{
"key": "cash",
"desc": "Anticipo",
"description": "Anticipo",
"percent": "10.0%",
"amount": "2.20"
},
{
"key": "card",
"desc": "Saldo",
"description": "Saldo",
"percent": "90.0%",
"amount": "19.84"
}
Expand Down

0 comments on commit b09272a

Please sign in to comment.