v0.0.300 add custom unmarshal-hooks to wmo
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m45s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m45s
This commit is contained in:
@@ -12,6 +12,11 @@ func (c *Coll[TData]) decodeSingle(ctx context.Context, dec Decodable) (TData, e
|
||||
if err != nil {
|
||||
return *new(TData), exerr.Wrap(err, "failed to decode single entity with custom-decoder").Type("decoder", *c.customDecoder).Build()
|
||||
}
|
||||
|
||||
for _, hook := range c.unmarshalHooks {
|
||||
res = hook(res)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
||||
} else {
|
||||
@@ -23,6 +28,10 @@ func (c *Coll[TData]) decodeSingle(ctx context.Context, dec Decodable) (TData, e
|
||||
return *new(TData), exerr.Wrap(err, "failed to decode single entity").Type("target-type", res).Build()
|
||||
}
|
||||
|
||||
for _, hook := range c.unmarshalHooks {
|
||||
res = hook(res)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
||||
}
|
||||
@@ -38,6 +47,9 @@ func (c *Coll[TData]) decodeAll(ctx context.Context, cursor Cursorable) ([]TData
|
||||
if err != nil {
|
||||
return nil, exerr.Wrap(err, "failed to decode entity with custom-decoder").Type("decoder", *c.customDecoder).Build()
|
||||
}
|
||||
for _, hook := range c.unmarshalHooks {
|
||||
entry = hook(entry)
|
||||
}
|
||||
res = append(res, entry)
|
||||
}
|
||||
|
||||
@@ -52,6 +64,12 @@ func (c *Coll[TData]) decodeAll(ctx context.Context, cursor Cursorable) ([]TData
|
||||
return nil, exerr.Wrap(err, "failed to batch-decode entity").Type("target-type", res).Build()
|
||||
}
|
||||
|
||||
for i := 0; i < len(res); i++ {
|
||||
for _, hook := range c.unmarshalHooks {
|
||||
res[i] = hook(res[i])
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user