Remove recordType and reserved fields #1070
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a bit scary, but it seems that
recordType
andreserved
fields don't really do anything. They are unexported, they are always set by each struct's correspondingNew
function, and they are effectively constants.The existence of these fields causes issues when marshalling & unmarshalling ACH data structures. Because
recordType
is unexported, it isn't included in the JSON blob produced by marshal. Then when the blob is unmarshalled, the absence ofrecordType
causes validation errors. This is addressed in a few different ways for different types:NewEntryDetail
return a new struct with defaults set. The blob can be unmarshalled into that struct and the unexported defaults remain.setEntryRecordType
iterates through each of anEntryDetail
's addenda fields and sets eachrecordTypes
(this is called byFileFromJSON
)Unmarshal
functions likebatch.UnmarshalJSON
populate fields with default structs before unmarshalling.The particular issue I'm running into is marshalling and unmarshalling
BatchHeaders
. This could be addressed by exportingsetEntryRecordType
or adding another custom Unmarshal function. But I think it would be even better if we could removerecordType
(andreserved
) altogether, and replace references to them with appropriate constants.