Skip to content

Commit

Permalink
fix: pointers in serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 29, 2023
1 parent a533a04 commit 497d811
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,26 @@ func Serialize(in map[string]any) (map[string]any, error) {
}

// cel supports time.Time and time.Duration natively - save original and then replace it after decomposition
nativeTypes := make(map[*jp.Expr]any)
nativeTypes := make(map[string]any, len(in))
jp.Walk(in, func(path jp.Expr, value any) {
switch v := value.(type) {
case time.Duration, time.Time:
nativeTypes[&path] = v
nativeTypes[path.String()] = v
}
})

out := alt.Alter(in, &opts).(map[string]any)

for path, v := range nativeTypes {
if err := path.SetOne(out, v); err != nil {
expr, err := jp.ParseString(path)
if err != nil {
return nil, err
}

if err := expr.SetOne(out, v); err != nil {
return nil, err
}
}

return out, nil
}

0 comments on commit 497d811

Please sign in to comment.