From ec0d97daea6cb21e4ec9bee5a308587ded10030c Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Wed, 28 Oct 2020 15:03:02 -0500 Subject: [PATCH] all: populate record tag after JSON unmarshal Due to the way Go initializes structs their fields cannot have a default value. This means we use exported constructors to populate them with hidden fields. When we unmarshal (via FileFromJSON) those hidden files are not populated, so we have to sneak their values in whenever someone uses json.Unmarshaler Fixes: https://github.com/moov-io/wire/issues/104 --- accountCreditedDrawdown.go | 15 +++++++++ accountDebitedDrawdown.go | 15 +++++++++ actualAmountPaid.go | 15 +++++++++ adjustment.go | 15 +++++++++ amount.go | 15 +++++++++ amountNegotiatedDiscount.go | 15 +++++++++ beneficiary.go | 15 +++++++++ beneficiaryCustomer.go | 15 +++++++++ beneficiaryFI.go | 15 +++++++++ beneficiaryIntermediaryFI.go | 15 +++++++++ beneficiaryReference.go | 15 +++++++++ businessFunctionCode.go | 15 +++++++++ charges.go | 15 +++++++++ currencyInstructedAmount.go | 15 +++++++++ dateRemittanceDocument.go | 15 +++++++++ errorWire.go | 19 +++++++++++- exchangeRate.go | 15 +++++++++ fIBeneficiaryFIAdvice.go | 15 +++++++++ fiAdditionalFIToFI.go | 15 +++++++++ fiBeneficiary.go | 15 +++++++++ fiBeneficiaryAdvice.go | 15 +++++++++ fiBeneficiaryFI.go | 15 +++++++++ fiDrawdownDebitAccountAdvice.go | 15 +++++++++ fiIntermediaryFI.go | 15 +++++++++ fiIntermediaryFIAdvice.go | 15 +++++++++ fiPaymentMethodToBeneficiary.go | 15 +++++++++ fiReceiverFI.go | 15 +++++++++ grossAmountRemittanceDocument.go | 15 +++++++++ inputMessageAccountabilityData.go | 15 +++++++++ institutionAccount.go | 15 +++++++++ instructedAmount.go | 15 +++++++++ instructingFI.go | 15 +++++++++ intermediaryInstitution.go | 15 +++++++++ issue104_test.go | 50 ++++++++++++++++++++++++++++++ localInstrument.go | 15 +++++++++ messageDisposition.go | 19 +++++++++++- orderingCustomer.go | 15 +++++++++ orderingInstitution.go | 15 +++++++++ originator.go | 15 +++++++++ originatorFI.go | 15 +++++++++ originatorOptionF.go | 15 +++++++++ originatorToBeneficiary.go | 15 +++++++++ outputMessageAccountabilityData.go | 19 +++++++++++- paymentNotification.go | 15 +++++++++ previousMessageIdentifier.go | 15 +++++++++ primaryRemittanceDocument.go | 15 +++++++++ receiptTimeStamp.go | 15 +++++++++ receiverDepositoryInstitution.go | 15 +++++++++ relatedRemittance.go | 15 +++++++++ remittance.go | 15 +++++++++ remittanceBeneficiary.go | 15 +++++++++ remittanceFreeText.go | 15 +++++++++ remittanceOriginator.go | 15 +++++++++ secondaryRemittanceDocument.go | 15 +++++++++ senderDepositoryInstitution.go | 15 +++++++++ senderReference.go | 15 +++++++++ senderSupplied.go | 15 +++++++++ senderToReceiver.go | 15 +++++++++ serviceMessage.go | 15 +++++++++ typeSubType.go | 15 +++++++++ unstructuredAddenda.go | 15 +++++++++ 61 files changed, 959 insertions(+), 3 deletions(-) create mode 100644 issue104_test.go diff --git a/accountCreditedDrawdown.go b/accountCreditedDrawdown.go index 166eaae8..639f7303 100644 --- a/accountCreditedDrawdown.go +++ b/accountCreditedDrawdown.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -43,6 +44,20 @@ func (creditDD *AccountCreditedDrawdown) Parse(record string) error { return nil } +func (creditDD *AccountCreditedDrawdown) UnmarshalJSON(data []byte) error { + type Alias AccountCreditedDrawdown + aux := struct { + *Alias + }{ + (*Alias)(creditDD), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + creditDD.tag = TagAccountCreditedDrawdown + return nil +} + // String writes AccountCreditedDrawdown func (creditDD *AccountCreditedDrawdown) String() string { var buf strings.Builder diff --git a/accountDebitedDrawdown.go b/accountDebitedDrawdown.go index 928d748a..7a217071 100644 --- a/accountDebitedDrawdown.go +++ b/accountDebitedDrawdown.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -53,6 +54,20 @@ func (debitDD *AccountDebitedDrawdown) Parse(record string) error { return nil } +func (debitDD *AccountDebitedDrawdown) UnmarshalJSON(data []byte) error { + type Alias AccountDebitedDrawdown + aux := struct { + *Alias + }{ + (*Alias)(debitDD), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + debitDD.tag = TagAccountDebitedDrawdown + return nil +} + // String writes AccountDebitedDrawdown func (debitDD *AccountDebitedDrawdown) String() string { var buf strings.Builder diff --git a/actualAmountPaid.go b/actualAmountPaid.go index 53a463fb..902d7b99 100644 --- a/actualAmountPaid.go +++ b/actualAmountPaid.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -44,6 +45,20 @@ func (aap *ActualAmountPaid) Parse(record string) error { return nil } +func (aap *ActualAmountPaid) UnmarshalJSON(data []byte) error { + type Alias ActualAmountPaid + aux := struct { + *Alias + }{ + (*Alias)(aap), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + aap.tag = TagActualAmountPaid + return nil +} + // String writes ActualAmountPaid func (aap *ActualAmountPaid) String() string { var buf strings.Builder diff --git a/adjustment.go b/adjustment.go index 035be484..a3084ec7 100644 --- a/adjustment.go +++ b/adjustment.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -53,6 +54,20 @@ func (adj *Adjustment) Parse(record string) error { return nil } +func (adj *Adjustment) UnmarshalJSON(data []byte) error { + type Alias Adjustment + aux := struct { + *Alias + }{ + (*Alias)(adj), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + adj.tag = TagAdjustment + return nil +} + // String writes Adjustment func (adj *Adjustment) String() string { var buf strings.Builder diff --git a/amount.go b/amount.go index c9a9745f..f34c17ed 100644 --- a/amount.go +++ b/amount.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -43,6 +44,20 @@ func (a *Amount) Parse(record string) error { return nil } +func (a *Amount) UnmarshalJSON(data []byte) error { + type Alias Amount + aux := struct { + *Alias + }{ + (*Alias)(a), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + a.tag = TagAmount + return nil +} + // String writes Amount func (a *Amount) String() string { var buf strings.Builder diff --git a/amountNegotiatedDiscount.go b/amountNegotiatedDiscount.go index 345d8924..d004f088 100644 --- a/amountNegotiatedDiscount.go +++ b/amountNegotiatedDiscount.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -44,6 +45,20 @@ func (nd *AmountNegotiatedDiscount) Parse(record string) error { return nil } +func (nd *AmountNegotiatedDiscount) UnmarshalJSON(data []byte) error { + type Alias AmountNegotiatedDiscount + aux := struct { + *Alias + }{ + (*Alias)(nd), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + nd.tag = TagAmountNegotiatedDiscount + return nil +} + // String writes AmountNegotiatedDiscount func (nd *AmountNegotiatedDiscount) String() string { var buf strings.Builder diff --git a/beneficiary.go b/beneficiary.go index 85676886..0252dded 100644 --- a/beneficiary.go +++ b/beneficiary.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (ben *Beneficiary) Parse(record string) error { return nil } +func (ben *Beneficiary) UnmarshalJSON(data []byte) error { + type Alias Beneficiary + aux := struct { + *Alias + }{ + (*Alias)(ben), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ben.tag = TagBeneficiary + return nil +} + // String writes Beneficiary func (ben *Beneficiary) String() string { var buf strings.Builder diff --git a/beneficiaryCustomer.go b/beneficiaryCustomer.go index 4d120e34..08c5e597 100644 --- a/beneficiaryCustomer.go +++ b/beneficiaryCustomer.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (bc *BeneficiaryCustomer) Parse(record string) error { return nil } +func (bc *BeneficiaryCustomer) UnmarshalJSON(data []byte) error { + type Alias BeneficiaryCustomer + aux := struct { + *Alias + }{ + (*Alias)(bc), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + bc.tag = TagBeneficiaryCustomer + return nil +} + // String writes BeneficiaryCustomer func (bc *BeneficiaryCustomer) String() string { var buf strings.Builder diff --git a/beneficiaryFI.go b/beneficiaryFI.go index 162525c9..4c6728dd 100644 --- a/beneficiaryFI.go +++ b/beneficiaryFI.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (bfi *BeneficiaryFI) Parse(record string) error { return nil } +func (bfi *BeneficiaryFI) UnmarshalJSON(data []byte) error { + type Alias BeneficiaryFI + aux := struct { + *Alias + }{ + (*Alias)(bfi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + bfi.tag = TagBeneficiaryFI + return nil +} + // String writes BeneficiaryFI func (bfi *BeneficiaryFI) String() string { var buf strings.Builder diff --git a/beneficiaryIntermediaryFI.go b/beneficiaryIntermediaryFI.go index 81cb9a80..df314275 100644 --- a/beneficiaryIntermediaryFI.go +++ b/beneficiaryIntermediaryFI.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (bifi *BeneficiaryIntermediaryFI) Parse(record string) error { return nil } +func (bifi *BeneficiaryIntermediaryFI) UnmarshalJSON(data []byte) error { + type Alias BeneficiaryIntermediaryFI + aux := struct { + *Alias + }{ + (*Alias)(bifi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + bifi.tag = TagBeneficiaryIntermediaryFI + return nil +} + // String writes BeneficiaryIntermediaryFI func (bifi *BeneficiaryIntermediaryFI) String() string { var buf strings.Builder diff --git a/beneficiaryReference.go b/beneficiaryReference.go index f8c8d983..bfbc9c56 100644 --- a/beneficiaryReference.go +++ b/beneficiaryReference.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -43,6 +44,20 @@ func (br *BeneficiaryReference) Parse(record string) error { return nil } +func (br *BeneficiaryReference) UnmarshalJSON(data []byte) error { + type Alias BeneficiaryReference + aux := struct { + *Alias + }{ + (*Alias)(br), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + br.tag = TagBeneficiaryReference + return nil +} + // String writes BeneficiaryReference func (br *BeneficiaryReference) String() string { var buf strings.Builder diff --git a/businessFunctionCode.go b/businessFunctionCode.go index f7c91bf6..42975c39 100644 --- a/businessFunctionCode.go +++ b/businessFunctionCode.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -46,6 +47,20 @@ func (bfc *BusinessFunctionCode) Parse(record string) error { return nil } +func (bfc *BusinessFunctionCode) UnmarshalJSON(data []byte) error { + type Alias BusinessFunctionCode + aux := struct { + *Alias + }{ + (*Alias)(bfc), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + bfc.tag = TagBusinessFunctionCode + return nil +} + // String writes BusinessFunctionCode func (bfc *BusinessFunctionCode) String() string { var buf strings.Builder diff --git a/charges.go b/charges.go index d75fa62b..982ccfd4 100644 --- a/charges.go +++ b/charges.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -62,6 +63,20 @@ func (c *Charges) Parse(record string) { c.SendersChargesFour = c.parseStringField(record[52:67]) } +func (c *Charges) UnmarshalJSON(data []byte) error { + type Alias Charges + aux := struct { + *Alias + }{ + (*Alias)(c), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + c.tag = TagCharges + return nil +} + // String writes Charges func (c *Charges) String() string { var buf strings.Builder diff --git a/currencyInstructedAmount.go b/currencyInstructedAmount.go index 98278301..769ef53b 100644 --- a/currencyInstructedAmount.go +++ b/currencyInstructedAmount.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -47,6 +48,20 @@ func (cia *CurrencyInstructedAmount) Parse(record string) error { return nil } +func (cia *CurrencyInstructedAmount) UnmarshalJSON(data []byte) error { + type Alias CurrencyInstructedAmount + aux := struct { + *Alias + }{ + (*Alias)(cia), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + cia.tag = TagCurrencyInstructedAmount + return nil +} + // String writes CurrencyInstructedAmount func (cia *CurrencyInstructedAmount) String() string { var buf strings.Builder diff --git a/dateRemittanceDocument.go b/dateRemittanceDocument.go index c2a3adc3..c0b5af7c 100644 --- a/dateRemittanceDocument.go +++ b/dateRemittanceDocument.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -43,6 +44,20 @@ func (drd *DateRemittanceDocument) Parse(record string) error { return nil } +func (drd *DateRemittanceDocument) UnmarshalJSON(data []byte) error { + type Alias DateRemittanceDocument + aux := struct { + *Alias + }{ + (*Alias)(drd), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + drd.tag = TagDateRemittanceDocument + return nil +} + // String writes DateRemittanceDocument func (drd *DateRemittanceDocument) String() string { var buf strings.Builder diff --git a/errorWire.go b/errorWire.go index a525e24f..9676d415 100644 --- a/errorWire.go +++ b/errorWire.go @@ -4,7 +4,10 @@ package wire -import "strings" +import ( + "encoding/json" + "strings" +) // ErrorWire is a wire error with the fedwire message type ErrorWire struct { @@ -42,6 +45,20 @@ func (ew *ErrorWire) Parse(record string) { ew.ErrorDescription = ew.parseStringField(record[10:45]) } +func (ew *ErrorWire) UnmarshalJSON(data []byte) error { + type Alias ErrorWire + aux := struct { + *Alias + }{ + (*Alias)(ew), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ew.tag = TagErrorWire + return nil +} + // String writes ErrorWire func (ew *ErrorWire) String() string { var buf strings.Builder diff --git a/exchangeRate.go b/exchangeRate.go index 8421df15..d46f9be6 100644 --- a/exchangeRate.go +++ b/exchangeRate.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -44,6 +45,20 @@ func (eRate *ExchangeRate) Parse(record string) error { return nil } +func (eRate *ExchangeRate) UnmarshalJSON(data []byte) error { + type Alias ExchangeRate + aux := struct { + *Alias + }{ + (*Alias)(eRate), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + eRate.tag = TagExchangeRate + return nil +} + // String writes ExchangeRate func (eRate *ExchangeRate) String() string { var buf strings.Builder diff --git a/fIBeneficiaryFIAdvice.go b/fIBeneficiaryFIAdvice.go index 909fe38c..a08570d1 100644 --- a/fIBeneficiaryFIAdvice.go +++ b/fIBeneficiaryFIAdvice.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -49,6 +50,20 @@ func (fibfia *FIBeneficiaryFIAdvice) Parse(record string) error { return nil } +func (fibfia *FIBeneficiaryFIAdvice) UnmarshalJSON(data []byte) error { + type Alias FIBeneficiaryFIAdvice + aux := struct { + *Alias + }{ + (*Alias)(fibfia), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + fibfia.tag = TagFIBeneficiaryFIAdvice + return nil +} + // String writes FIBeneficiaryFIAdvice func (fibfia *FIBeneficiaryFIAdvice) String() string { var buf strings.Builder diff --git a/fiAdditionalFIToFI.go b/fiAdditionalFIToFI.go index 7989ff77..36eec804 100644 --- a/fiAdditionalFIToFI.go +++ b/fiAdditionalFIToFI.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (fifi *FIAdditionalFIToFI) Parse(record string) error { return nil } +func (fifi *FIAdditionalFIToFI) UnmarshalJSON(data []byte) error { + type Alias FIAdditionalFIToFI + aux := struct { + *Alias + }{ + (*Alias)(fifi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + fifi.tag = TagFIAdditionalFIToFI + return nil +} + // String writes FIAdditionalFIToFI func (fifi *FIAdditionalFIToFI) String() string { var buf strings.Builder diff --git a/fiBeneficiary.go b/fiBeneficiary.go index ffd0d82e..5462ac41 100644 --- a/fiBeneficiary.go +++ b/fiBeneficiary.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (fib *FIBeneficiary) Parse(record string) error { return nil } +func (fib *FIBeneficiary) UnmarshalJSON(data []byte) error { + type Alias FIBeneficiary + aux := struct { + *Alias + }{ + (*Alias)(fib), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + fib.tag = TagFIBeneficiary + return nil +} + // String writes FIBeneficiary func (fib *FIBeneficiary) String() string { var buf strings.Builder diff --git a/fiBeneficiaryAdvice.go b/fiBeneficiaryAdvice.go index eb36d76f..da905038 100644 --- a/fiBeneficiaryAdvice.go +++ b/fiBeneficiaryAdvice.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -49,6 +50,20 @@ func (fiba *FIBeneficiaryAdvice) Parse(record string) error { return nil } +func (fiba *FIBeneficiaryAdvice) UnmarshalJSON(data []byte) error { + type Alias FIBeneficiaryAdvice + aux := struct { + *Alias + }{ + (*Alias)(fiba), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + fiba.tag = TagFIBeneficiaryAdvice + return nil +} + // String writes FIBeneficiaryAdvice func (fiba *FIBeneficiaryAdvice) String() string { var buf strings.Builder diff --git a/fiBeneficiaryFI.go b/fiBeneficiaryFI.go index b310da43..7e3a19c4 100644 --- a/fiBeneficiaryFI.go +++ b/fiBeneficiaryFI.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (fibfi *FIBeneficiaryFI) Parse(record string) error { return nil } +func (fibfi *FIBeneficiaryFI) UnmarshalJSON(data []byte) error { + type Alias FIBeneficiaryFI + aux := struct { + *Alias + }{ + (*Alias)(fibfi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + fibfi.tag = TagFIBeneficiaryFI + return nil +} + // String writes FIBeneficiaryFI func (fibfi *FIBeneficiaryFI) String() string { var buf strings.Builder diff --git a/fiDrawdownDebitAccountAdvice.go b/fiDrawdownDebitAccountAdvice.go index a4aed32d..50ce90ec 100644 --- a/fiDrawdownDebitAccountAdvice.go +++ b/fiDrawdownDebitAccountAdvice.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -49,6 +50,20 @@ func (debitDDAdvice *FIDrawdownDebitAccountAdvice) Parse(record string) error { return nil } +func (debitDDAdvice *FIDrawdownDebitAccountAdvice) UnmarshalJSON(data []byte) error { + type Alias FIDrawdownDebitAccountAdvice + aux := struct { + *Alias + }{ + (*Alias)(debitDDAdvice), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + debitDDAdvice.tag = TagFIDrawdownDebitAccountAdvice + return nil +} + // String writes FIDrawdownDebitAccountAdvice func (debitDDAdvice *FIDrawdownDebitAccountAdvice) String() string { var buf strings.Builder diff --git a/fiIntermediaryFI.go b/fiIntermediaryFI.go index 6c253cb4..d85c41f5 100644 --- a/fiIntermediaryFI.go +++ b/fiIntermediaryFI.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (fiifi *FIIntermediaryFI) Parse(record string) error { return nil } +func (fiifi *FIIntermediaryFI) UnmarshalJSON(data []byte) error { + type Alias FIIntermediaryFI + aux := struct { + *Alias + }{ + (*Alias)(fiifi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + fiifi.tag = TagFIIntermediaryFI + return nil +} + // String writes FIIntermediaryFI func (fiifi *FIIntermediaryFI) String() string { var buf strings.Builder diff --git a/fiIntermediaryFIAdvice.go b/fiIntermediaryFIAdvice.go index bf1cfc31..4f400aab 100644 --- a/fiIntermediaryFIAdvice.go +++ b/fiIntermediaryFIAdvice.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -49,6 +50,20 @@ func (fiifia *FIIntermediaryFIAdvice) Parse(record string) error { return nil } +func (fiifia *FIIntermediaryFIAdvice) UnmarshalJSON(data []byte) error { + type Alias FIIntermediaryFIAdvice + aux := struct { + *Alias + }{ + (*Alias)(fiifia), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + fiifia.tag = TagFIIntermediaryFIAdvice + return nil +} + // String writes FIIntermediaryFIAdvice func (fiifia *FIIntermediaryFIAdvice) String() string { var buf strings.Builder diff --git a/fiPaymentMethodToBeneficiary.go b/fiPaymentMethodToBeneficiary.go index 5c8c5ac5..aa86ff81 100644 --- a/fiPaymentMethodToBeneficiary.go +++ b/fiPaymentMethodToBeneficiary.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -47,6 +48,20 @@ func (pm *FIPaymentMethodToBeneficiary) Parse(record string) error { return nil } +func (pm *FIPaymentMethodToBeneficiary) UnmarshalJSON(data []byte) error { + type Alias FIPaymentMethodToBeneficiary + aux := struct { + *Alias + }{ + (*Alias)(pm), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + pm.tag = TagFIPaymentMethodToBeneficiary + return nil +} + // String writes FIPaymentMethodToBeneficiary func (pm *FIPaymentMethodToBeneficiary) String() string { var buf strings.Builder diff --git a/fiReceiverFI.go b/fiReceiverFI.go index d25a8104..bac6c9b2 100644 --- a/fiReceiverFI.go +++ b/fiReceiverFI.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (firfi *FIReceiverFI) Parse(record string) error { return nil } +func (firfi *FIReceiverFI) UnmarshalJSON(data []byte) error { + type Alias FIReceiverFI + aux := struct { + *Alias + }{ + (*Alias)(firfi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + firfi.tag = TagFIReceiverFI + return nil +} + // String writes FIReceiverFI func (firfi *FIReceiverFI) String() string { var buf strings.Builder diff --git a/grossAmountRemittanceDocument.go b/grossAmountRemittanceDocument.go index 655dbeb3..53434274 100644 --- a/grossAmountRemittanceDocument.go +++ b/grossAmountRemittanceDocument.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -44,6 +45,20 @@ func (gard *GrossAmountRemittanceDocument) Parse(record string) error { return nil } +func (gard *GrossAmountRemittanceDocument) UnmarshalJSON(data []byte) error { + type Alias GrossAmountRemittanceDocument + aux := struct { + *Alias + }{ + (*Alias)(gard), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + gard.tag = TagGrossAmountRemittanceDocument + return nil +} + // String writes GrossAmountRemittanceDocument func (gard *GrossAmountRemittanceDocument) String() string { var buf strings.Builder diff --git a/inputMessageAccountabilityData.go b/inputMessageAccountabilityData.go index 3b94a03e..fe50bf2e 100644 --- a/inputMessageAccountabilityData.go +++ b/inputMessageAccountabilityData.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -49,6 +50,20 @@ func (imad *InputMessageAccountabilityData) Parse(record string) error { return nil } +func (imad *InputMessageAccountabilityData) UnmarshalJSON(data []byte) error { + type Alias InputMessageAccountabilityData + aux := struct { + *Alias + }{ + (*Alias)(imad), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + imad.tag = TagInputMessageAccountabilityData + return nil +} + // String writes InputMessageAccountabilityData func (imad *InputMessageAccountabilityData) String() string { var buf strings.Builder diff --git a/institutionAccount.go b/institutionAccount.go index 18abb781..a7b98faa 100644 --- a/institutionAccount.go +++ b/institutionAccount.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (iAccount *InstitutionAccount) Parse(record string) error { return nil } +func (iAccount *InstitutionAccount) UnmarshalJSON(data []byte) error { + type Alias InstitutionAccount + aux := struct { + *Alias + }{ + (*Alias)(iAccount), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + iAccount.tag = TagInstitutionAccount + return nil +} + // String writes InstitutionAccount func (iAccount *InstitutionAccount) String() string { var buf strings.Builder diff --git a/instructedAmount.go b/instructedAmount.go index 29ef51fc..80209e64 100644 --- a/instructedAmount.go +++ b/instructedAmount.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -47,6 +48,20 @@ func (ia *InstructedAmount) Parse(record string) error { return nil } +func (ia *InstructedAmount) UnmarshalJSON(data []byte) error { + type Alias InstructedAmount + aux := struct { + *Alias + }{ + (*Alias)(ia), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ia.tag = TagInstructedAmount + return nil +} + // String writes InstructedAmount func (ia *InstructedAmount) String() string { var buf strings.Builder diff --git a/instructingFI.go b/instructingFI.go index 30f1db44..28d9da5a 100644 --- a/instructingFI.go +++ b/instructingFI.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (ifi *InstructingFI) Parse(record string) error { return nil } +func (ifi *InstructingFI) UnmarshalJSON(data []byte) error { + type Alias InstructingFI + aux := struct { + *Alias + }{ + (*Alias)(ifi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ifi.tag = TagInstructingFI + return nil +} + // String writes InstructingFI func (ifi *InstructingFI) String() string { var buf strings.Builder diff --git a/intermediaryInstitution.go b/intermediaryInstitution.go index 7d89aea6..3621a404 100644 --- a/intermediaryInstitution.go +++ b/intermediaryInstitution.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (ii *IntermediaryInstitution) Parse(record string) error { return nil } +func (ii *IntermediaryInstitution) UnmarshalJSON(data []byte) error { + type Alias IntermediaryInstitution + aux := struct { + *Alias + }{ + (*Alias)(ii), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ii.tag = TagIntermediaryInstitution + return nil +} + // String writes IntermediaryInstitution func (ii *IntermediaryInstitution) String() string { var buf strings.Builder diff --git a/issue104_test.go b/issue104_test.go new file mode 100644 index 00000000..3fecb9f4 --- /dev/null +++ b/issue104_test.go @@ -0,0 +1,50 @@ +// Copyright 2020 The Moov Authors +// Use of this source code is governed by an Apache License +// license that can be found in the LICENSE file. + +package wire + +import ( + "bytes" + "io/ioutil" + "path/filepath" + "strings" + "testing" +) + +func TestIssue104(t *testing.T) { + bs, err := ioutil.ReadFile(filepath.Join("test", "testdata", "fedWireMessage-BankTransfer.json")) + if err != nil { + t.Fatal(err) + } + + file, err := FileFromJSON(bs) + if err != nil { + t.Fatal(err) + } + if file == nil { + t.Fatal("nil File") + } + + var buf bytes.Buffer + if err := NewWriter(&buf).Write(file); err != nil { + t.Fatal(err) + } + + // verify the output + lines := strings.Split(buf.String(), "\n") + if n := len(lines); n != 27 { + t.Errorf("got %d lines", n) + } + for i := range lines { + if lines[i] == "" { + continue + } + + prefix := string(lines[i][0:6]) + // tags are 4 digits surrounded by {..} - example: {1500} + if prefix[0] != '{' || prefix[5] != '}' { + t.Errorf("index #%d - missing tag: %q", i, prefix) + } + } +} diff --git a/localInstrument.go b/localInstrument.go index 6be1ed59..522ece8a 100644 --- a/localInstrument.go +++ b/localInstrument.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -46,6 +47,20 @@ func (li *LocalInstrument) Parse(record string) error { return nil } +func (li *LocalInstrument) UnmarshalJSON(data []byte) error { + type Alias LocalInstrument + aux := struct { + *Alias + }{ + (*Alias)(li), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + li.tag = TagLocalInstrument + return nil +} + // String writes LocalInstrument func (li *LocalInstrument) String() string { var buf strings.Builder diff --git a/messageDisposition.go b/messageDisposition.go index f74957aa..869f90cb 100644 --- a/messageDisposition.go +++ b/messageDisposition.go @@ -4,7 +4,10 @@ package wire -import "strings" +import ( + "encoding/json" + "strings" +) // MessageDisposition is the message disposition of the wire type MessageDisposition struct { @@ -48,6 +51,20 @@ func (md *MessageDisposition) Parse(record string) { md.MessageStatusIndicator = md.parseStringField(record[10:11]) } +func (md *MessageDisposition) UnmarshalJSON(data []byte) error { + type Alias MessageDisposition + aux := struct { + *Alias + }{ + (*Alias)(md), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + md.tag = TagMessageDisposition + return nil +} + // String writes MessageDisposition func (md *MessageDisposition) String() string { var buf strings.Builder diff --git a/orderingCustomer.go b/orderingCustomer.go index 2c431c92..699dfb48 100644 --- a/orderingCustomer.go +++ b/orderingCustomer.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (oc *OrderingCustomer) Parse(record string) error { return nil } +func (oc *OrderingCustomer) UnmarshalJSON(data []byte) error { + type Alias OrderingCustomer + aux := struct { + *Alias + }{ + (*Alias)(oc), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + oc.tag = TagOrderingCustomer + return nil +} + // String writes OrderingCustomer func (oc *OrderingCustomer) String() string { var buf strings.Builder diff --git a/orderingInstitution.go b/orderingInstitution.go index e0c9d97d..164f123b 100644 --- a/orderingInstitution.go +++ b/orderingInstitution.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (oi *OrderingInstitution) Parse(record string) error { return nil } +func (oi *OrderingInstitution) UnmarshalJSON(data []byte) error { + type Alias OrderingInstitution + aux := struct { + *Alias + }{ + (*Alias)(oi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + oi.tag = TagOrderingInstitution + return nil +} + // String writes OrderingInstitution func (oi *OrderingInstitution) String() string { var buf strings.Builder diff --git a/originator.go b/originator.go index 617f5e5e..1d6e81e1 100644 --- a/originator.go +++ b/originator.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -47,6 +48,20 @@ func (o *Originator) Parse(record string) error { return nil } +func (o *Originator) UnmarshalJSON(data []byte) error { + type Alias Originator + aux := struct { + *Alias + }{ + (*Alias)(o), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + o.tag = TagOriginator + return nil +} + // String writes Originator func (o *Originator) String() string { var buf strings.Builder diff --git a/originatorFI.go b/originatorFI.go index 9774f959..f7841818 100644 --- a/originatorFI.go +++ b/originatorFI.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -48,6 +49,20 @@ func (ofi *OriginatorFI) Parse(record string) error { return nil } +func (ofi *OriginatorFI) UnmarshalJSON(data []byte) error { + type Alias OriginatorFI + aux := struct { + *Alias + }{ + (*Alias)(ofi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ofi.tag = TagOriginatorFI + return nil +} + // String writes OriginatorFI func (ofi *OriginatorFI) String() string { var buf strings.Builder diff --git a/originatorOptionF.go b/originatorOptionF.go index db5a08ff..2ce6b154 100644 --- a/originatorOptionF.go +++ b/originatorOptionF.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -111,6 +112,20 @@ func (oof *OriginatorOptionF) Parse(record string) error { return nil } +func (oof *OriginatorOptionF) UnmarshalJSON(data []byte) error { + type Alias OriginatorOptionF + aux := struct { + *Alias + }{ + (*Alias)(oof), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + oof.tag = TagOriginatorOptionF + return nil +} + // String writes OriginatorOptionF func (oof *OriginatorOptionF) String() string { var buf strings.Builder diff --git a/originatorToBeneficiary.go b/originatorToBeneficiary.go index 65b47d38..98d2b3f8 100644 --- a/originatorToBeneficiary.go +++ b/originatorToBeneficiary.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -52,6 +53,20 @@ func (ob *OriginatorToBeneficiary) Parse(record string) error { return nil } +func (ob *OriginatorToBeneficiary) UnmarshalJSON(data []byte) error { + type Alias OriginatorToBeneficiary + aux := struct { + *Alias + }{ + (*Alias)(ob), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ob.tag = TagOriginatorToBeneficiary + return nil +} + // String writes OriginatorToBeneficiary func (ob *OriginatorToBeneficiary) String() string { var buf strings.Builder diff --git a/outputMessageAccountabilityData.go b/outputMessageAccountabilityData.go index 3532d221..cd9fa6f6 100644 --- a/outputMessageAccountabilityData.go +++ b/outputMessageAccountabilityData.go @@ -4,7 +4,10 @@ package wire -import "strings" +import ( + "encoding/json" + "strings" +) // OutputMessageAccountabilityData is the Output Message Accountability Data (OMAD) of the wire type OutputMessageAccountabilityData struct { @@ -51,6 +54,20 @@ func (omad *OutputMessageAccountabilityData) Parse(record string) { omad.OutputFRBApplicationIdentification = omad.parseStringField(record[36:40]) } +func (omad *OutputMessageAccountabilityData) UnmarshalJSON(data []byte) error { + type Alias OutputMessageAccountabilityData + aux := struct { + *Alias + }{ + (*Alias)(omad), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + omad.tag = TagOutputMessageAccountabilityData + return nil +} + // String writes OutputMessageAccountabilityData func (omad *OutputMessageAccountabilityData) String() string { var buf strings.Builder diff --git a/paymentNotification.go b/paymentNotification.go index 0bfdb21e..ed39b948 100644 --- a/paymentNotification.go +++ b/paymentNotification.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -63,6 +64,20 @@ func (pn *PaymentNotification) Parse(record string) error { return nil } +func (pn *PaymentNotification) UnmarshalJSON(data []byte) error { + type Alias PaymentNotification + aux := struct { + *Alias + }{ + (*Alias)(pn), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + pn.tag = TagPaymentNotification + return nil +} + // String writes PaymentNotification func (pn *PaymentNotification) String() string { var buf strings.Builder diff --git a/previousMessageIdentifier.go b/previousMessageIdentifier.go index 6e6b28fc..c91d0773 100644 --- a/previousMessageIdentifier.go +++ b/previousMessageIdentifier.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -43,6 +44,20 @@ func (pmi *PreviousMessageIdentifier) Parse(record string) error { return nil } +func (pmi *PreviousMessageIdentifier) UnmarshalJSON(data []byte) error { + type Alias PreviousMessageIdentifier + aux := struct { + *Alias + }{ + (*Alias)(pmi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + pmi.tag = TagPreviousMessageIdentifier + return nil +} + // String writes PreviousMessageIdentifier func (pmi *PreviousMessageIdentifier) String() string { var buf strings.Builder diff --git a/primaryRemittanceDocument.go b/primaryRemittanceDocument.go index e6f0e072..e037dc9c 100644 --- a/primaryRemittanceDocument.go +++ b/primaryRemittanceDocument.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -52,6 +53,20 @@ func (prd *PrimaryRemittanceDocument) Parse(record string) error { return nil } +func (prd *PrimaryRemittanceDocument) UnmarshalJSON(data []byte) error { + type Alias PrimaryRemittanceDocument + aux := struct { + *Alias + }{ + (*Alias)(prd), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + prd.tag = TagPrimaryRemittanceDocument + return nil +} + // String writes PrimaryRemittanceDocument func (prd *PrimaryRemittanceDocument) String() string { var buf strings.Builder diff --git a/receiptTimeStamp.go b/receiptTimeStamp.go index 5c3806c5..ab8b9419 100644 --- a/receiptTimeStamp.go +++ b/receiptTimeStamp.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -50,6 +51,20 @@ func (rts *ReceiptTimeStamp) Parse(record string) error { return nil } +func (rts *ReceiptTimeStamp) UnmarshalJSON(data []byte) error { + type Alias ReceiptTimeStamp + aux := struct { + *Alias + }{ + (*Alias)(rts), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + rts.tag = TagReceiptTimeStamp + return nil +} + // String writes ReceiptTimeStamp func (rts *ReceiptTimeStamp) String() string { var buf strings.Builder diff --git a/receiverDepositoryInstitution.go b/receiverDepositoryInstitution.go index f3ff97bb..d6bcb6ee 100644 --- a/receiverDepositoryInstitution.go +++ b/receiverDepositoryInstitution.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -46,6 +47,20 @@ func (rdi *ReceiverDepositoryInstitution) Parse(record string) error { return nil } +func (rdi *ReceiverDepositoryInstitution) UnmarshalJSON(data []byte) error { + type Alias ReceiverDepositoryInstitution + aux := struct { + *Alias + }{ + (*Alias)(rdi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + rdi.tag = TagReceiverDepositoryInstitution + return nil +} + // String writes ReceiverDepositoryInstitution func (rdi *ReceiverDepositoryInstitution) String() string { var buf strings.Builder diff --git a/relatedRemittance.go b/relatedRemittance.go index 9c4ae9bf..73ae8235 100644 --- a/relatedRemittance.go +++ b/relatedRemittance.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -68,6 +69,20 @@ func (rr *RelatedRemittance) Parse(record string) error { return nil } +func (rr *RelatedRemittance) UnmarshalJSON(data []byte) error { + type Alias RelatedRemittance + aux := struct { + *Alias + }{ + (*Alias)(rr), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + rr.tag = TagRelatedRemittance + return nil +} + // String writes RelatedRemittance func (rr *RelatedRemittance) String() string { var buf strings.Builder diff --git a/remittance.go b/remittance.go index cedce1ea..3f4b126b 100644 --- a/remittance.go +++ b/remittance.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -47,6 +48,20 @@ func (ri *Remittance) Parse(record string) error { return nil } +func (ri *Remittance) UnmarshalJSON(data []byte) error { + type Alias Remittance + aux := struct { + *Alias + }{ + (*Alias)(ri), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ri.tag = TagRemittance + return nil +} + // String writes Remittance func (ri *Remittance) String() string { var buf strings.Builder diff --git a/remittanceBeneficiary.go b/remittanceBeneficiary.go index c000e6eb..48e31e4a 100644 --- a/remittanceBeneficiary.go +++ b/remittanceBeneficiary.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -73,6 +74,20 @@ func (rb *RemittanceBeneficiary) Parse(record string) error { return nil } +func (rb *RemittanceBeneficiary) UnmarshalJSON(data []byte) error { + type Alias RemittanceBeneficiary + aux := struct { + *Alias + }{ + (*Alias)(rb), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + rb.tag = TagRemittanceBeneficiary + return nil +} + // String writes RemittanceBeneficiary func (rb *RemittanceBeneficiary) String() string { var buf strings.Builder diff --git a/remittanceFreeText.go b/remittanceFreeText.go index fa692f4d..a881ec4b 100644 --- a/remittanceFreeText.go +++ b/remittanceFreeText.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -49,6 +50,20 @@ func (rft *RemittanceFreeText) Parse(record string) error { return nil } +func (rft *RemittanceFreeText) UnmarshalJSON(data []byte) error { + type Alias RemittanceFreeText + aux := struct { + *Alias + }{ + (*Alias)(rft), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + rft.tag = TagRemittanceFreeText + return nil +} + // String writes RemittanceFreeText func (rft *RemittanceFreeText) String() string { var buf strings.Builder diff --git a/remittanceOriginator.go b/remittanceOriginator.go index 13579d4a..7a25940a 100644 --- a/remittanceOriginator.go +++ b/remittanceOriginator.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -91,6 +92,20 @@ func (ro *RemittanceOriginator) Parse(record string) error { return nil } +func (ro *RemittanceOriginator) UnmarshalJSON(data []byte) error { + type Alias RemittanceOriginator + aux := struct { + *Alias + }{ + (*Alias)(ro), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ro.tag = TagRemittanceOriginator + return nil +} + // String writes RemittanceOriginator func (ro *RemittanceOriginator) String() string { var buf strings.Builder diff --git a/secondaryRemittanceDocument.go b/secondaryRemittanceDocument.go index bca5f35c..9484d652 100644 --- a/secondaryRemittanceDocument.go +++ b/secondaryRemittanceDocument.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -52,6 +53,20 @@ func (srd *SecondaryRemittanceDocument) Parse(record string) error { return nil } +func (srd *SecondaryRemittanceDocument) UnmarshalJSON(data []byte) error { + type Alias SecondaryRemittanceDocument + aux := struct { + *Alias + }{ + (*Alias)(srd), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + srd.tag = TagSecondaryRemittanceDocument + return nil +} + // String writes SecondaryRemittanceDocument func (srd *SecondaryRemittanceDocument) String() string { var buf strings.Builder diff --git a/senderDepositoryInstitution.go b/senderDepositoryInstitution.go index 7ef56a3e..b78fe885 100644 --- a/senderDepositoryInstitution.go +++ b/senderDepositoryInstitution.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -47,6 +48,20 @@ func (sdi *SenderDepositoryInstitution) Parse(record string) error { return nil } +func (sdi *SenderDepositoryInstitution) UnmarshalJSON(data []byte) error { + type Alias SenderDepositoryInstitution + aux := struct { + *Alias + }{ + (*Alias)(sdi), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + sdi.tag = TagSenderDepositoryInstitution + return nil +} + // String writes SenderDepositoryInstitution func (sdi *SenderDepositoryInstitution) String() string { var buf strings.Builder diff --git a/senderReference.go b/senderReference.go index aa684ac6..b696b7cd 100644 --- a/senderReference.go +++ b/senderReference.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -43,6 +44,20 @@ func (sr *SenderReference) Parse(record string) error { return nil } +func (sr *SenderReference) UnmarshalJSON(data []byte) error { + type Alias SenderReference + aux := struct { + *Alias + }{ + (*Alias)(sr), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + sr.tag = TagSenderReference + return nil +} + // String writes SenderReference func (sr *SenderReference) String() string { var buf strings.Builder diff --git a/senderSupplied.go b/senderSupplied.go index cfba4ecb..233f0603 100644 --- a/senderSupplied.go +++ b/senderSupplied.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -55,6 +56,20 @@ func (ss *SenderSupplied) Parse(record string) error { return nil } +func (ss *SenderSupplied) UnmarshalJSON(data []byte) error { + type Alias SenderSupplied + aux := struct { + *Alias + }{ + (*Alias)(ss), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ss.tag = TagSenderSupplied + return nil +} + // String writes SenderSupplied func (ss *SenderSupplied) String() string { var buf strings.Builder diff --git a/senderToReceiver.go b/senderToReceiver.go index af84bb9d..163db1d9 100644 --- a/senderToReceiver.go +++ b/senderToReceiver.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -49,6 +50,20 @@ func (str *SenderToReceiver) Parse(record string) error { return nil } +func (str *SenderToReceiver) UnmarshalJSON(data []byte) error { + type Alias SenderToReceiver + aux := struct { + *Alias + }{ + (*Alias)(str), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + str.tag = TagSenderToReceiver + return nil +} + // String writes SenderToReceiver func (str *SenderToReceiver) String() string { var buf strings.Builder diff --git a/serviceMessage.go b/serviceMessage.go index 6c02874d..be0fa6f2 100644 --- a/serviceMessage.go +++ b/serviceMessage.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -76,6 +77,20 @@ func (sm *ServiceMessage) Parse(record string) error { return nil } +func (sm *ServiceMessage) UnmarshalJSON(data []byte) error { + type Alias ServiceMessage + aux := struct { + *Alias + }{ + (*Alias)(sm), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + sm.tag = TagServiceMessage + return nil +} + // String writes ServiceMessage func (sm *ServiceMessage) String() string { var buf strings.Builder diff --git a/typeSubType.go b/typeSubType.go index 47e0327e..13a35e4b 100644 --- a/typeSubType.go +++ b/typeSubType.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -46,6 +47,20 @@ func (tst *TypeSubType) Parse(record string) error { return nil } +func (tst *TypeSubType) UnmarshalJSON(data []byte) error { + type Alias TypeSubType + aux := struct { + *Alias + }{ + (*Alias)(tst), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + tst.tag = TagTypeSubType + return nil +} + // String writes TypeSubType func (tst *TypeSubType) String() string { var buf strings.Builder diff --git a/unstructuredAddenda.go b/unstructuredAddenda.go index d37fb355..ad2a1925 100644 --- a/unstructuredAddenda.go +++ b/unstructuredAddenda.go @@ -5,6 +5,7 @@ package wire import ( + "encoding/json" "strings" "unicode/utf8" ) @@ -52,6 +53,20 @@ func (ua *UnstructuredAddenda) Parse(record string) error { return nil } +func (ua *UnstructuredAddenda) UnmarshalJSON(data []byte) error { + type Alias UnstructuredAddenda + aux := struct { + *Alias + }{ + (*Alias)(ua), + } + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + ua.tag = TagUnstructuredAddenda + return nil +} + // String writes UnstructuredAddenda func (ua *UnstructuredAddenda) String() string { var buf strings.Builder