Releases: soranoba/henge
Releases · soranoba/henge
v2.1.0
New Features
We have added callbacks for performing additional processing during struct conversion.
Previously, when converting structs that across packages, callbacks could only be written for one of conversion. With this update, you can now write callbacks for both.
Please refer to BeforeConvertFromCallback, BeforeConvertToCallback, AfterConvertFromCallback, and AfterConvertToCallback for more details.
Deprecated
Old | New |
---|---|
BeforeConvertCallback | BeforeConvertFromCallback |
AfterConvertCallback | AfterConvertFromCallback |
v2.0.0 (Enhanced map conversion)
Breaking Changes
Behavior
src := map[string]interface{}{
"a": map[string]interface{}{"a.1": "a.1"},
}
var dst map[string]interface{}
henge.New(src).Map().Convert(&dst)
v1: Type of dst["a"]
is map[string]interface{}
v2: Type of dst["b"]
is map[interface{}]interface{}
This means that it may be converted to a non-json-marshalable type from json-marshalable type.
You should replace it with the following method if necessary.
henge.New(src).JSONObject().Convert(&dst)
henge.New(src, henge.WithMapMaxDepth(0)).Convert(&dst)
Interface changes
type BeforeCallback interface {
- BeforeConvert(src interface{}, converter Converter) error
+ BeforeConvert(src interface{}, store InstanceStore) error
}
type AfterCallback interface {
- AfterConvert(src interface{}, converter Converter) error
+ AfterConvert(src interface{}, store InstanceStore) error
}
Renames
v1 | v2 | |
---|---|---|
type | func(*ConverterOpts) |
ConverterOption |
interface | Converter |
InstanceStore |
method | ValueConverter.JSONMap() |
ValueConverter.JSONObject() |
struct | JSONMapConverter |
JSONObjectConverter |
method | ValueConverter. FloatrPtr() |
ValueConverter.FloatPtr() |
New Features
New Conversions
- JSONValue
- JSONArray
- JSONObject
New Options
- WithSliceValueConverter
- WithMapKeyConverter
- WithMapValueConverter
- WithMapStructValueConverter
- WithMapTimeValueStringConverter
Bug fixes
- #8 : ValueConverter.Value() returns incorrect value when srcValue is nil.