Releases: scriptnull/jsonseal
Release list
v0.3.0
Unmarshal and Decode
This release makes Unmarshal and Decode functions to accept any value instead of jsonseal.Validator values.
var paymentRequest PaymentRequest
err := jsonseal.Unmarshal(paymentRequestWithInsufficientFunds, &paymentRequest)
// before:
// &paymentRequest must implement `jsonseal.Validator`
//
// after:
// &paymentRequest may or may not implement `jsonseal.Validator`
// if implemented, validation will take place after unmarshalling.Having the signature to be the same as the standard library json methods helps in replacing the standard library calls with the jsonseal methods in one go. This avoids forcing the user to immediately implement jsonseal.Validator on all of their structs. So that they can take an incremental approach in adopting jsonseal in their codebase.
Idiomatic Go
Now that Unmarshal and Decode doesn't ensure compile time guarantee that the passed struct implements the Validator interface, you can compensate for it by using a snippet like below.
var _ jsonseal.Validator = &PaymentRequest{}
// throws a compile time error if `PaymentRequest` doesn't implement `jsonseal.Validator` interfaceTwo new methods
UnmarshalValidate and DecodeValidate are now available which are like Unmarshal and Decode but ensure at compile time that the input value implements the jsonseal.Validator interface. This is an alternative to the snippet suggested above for getting the compile time guarantee.
In the case of Unmarshal and Decode, the validation happens silently after the json unmarshalling is done. But some folks might prefer calling it out explicitly for readability. These methods are available for such use cases.
v0.2.1
This is a bug fix for v0.2.0.
This enforces jsonseal.NewDecoder(data).Decode(v any) to become jsonseal.NewDecoder(data).Decode(v jsonseal.Validator). This will make the user to implement jsonseal.Validator interface on all structs that will be used for decoding.
v0.2.0
This release covers two major improvments.
Drop-in replacement for json.Decoder
err = json.NewDecoder(data).Decode(&v)
// could be replaced with
err = jsonseal.NewDecoder(data).Decode(&v)Unknown Field Suggestions
A method called WithUnknownFieldSuggestion() is now available for jsonseal.Decoder. This could be used to validate if the data contains only the allowed json fields defined in the struct that it is decoded to. Please refer this documentation section for more details.
v0.1.0
This is the initial release of jsonseal 🎉
It contains the following goodies:
jsonseal.CheckGroupAPI for writing validation requests'- Different error formatters like
jsonseal.JSONFormat - Ability to associate json fields with the validation errors via
FieldandFieldf
Please refer to the README.md file for a comprehensive walkthrough.