Skip to content

Commit

Permalink
Merge pull request #16 from jaksonlin/develop
Browse files Browse the repository at this point in the history
omit empy implementation through plugin incorrect, revoke
  • Loading branch information
jaksonlin authored Oct 15, 2023
2 parents f83c5ab + e5daf7c commit 1907df2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 56 deletions.
51 changes: 0 additions & 51 deletions astbuilder/golang/astPlugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,54 +113,3 @@ func arrayNodeFromStringNode(nodeValue string) (*ast.JsonArrayNode, error) {
return rs, nil

}

var omitEmptyPlugin ast.ASTNodePlugin = ast.NewASTNodePlugin(PLUGIN_OMITEMPTY, omitEmptyConversion, nil)

func omitEmptyConversion(visitor ast.JsonVisitor, node ast.JsonNode) error {
// this is a struct field, we need to omit it if the value is empty
node, ok := node.(*ast.JsonKeyValuePairNode)
if !ok {
return nil
}
switch valueNode := node.(type) {
case *ast.JsonStringNode:
val, err := valueNode.GetValue()
if err != nil {
return err
}
if val == "" {
node.SetVisited()
return nil
}
case *ast.JsonNumberNode:
if valueNode.Value == 0 {
node.SetVisited()
return nil
}
case *ast.JsonBooleanNode:
if !valueNode.Value {
node.SetVisited()
return nil
}
case *ast.JsonNullNode:
node.SetVisited()
return nil
case *ast.JsonArrayNode:
if valueNode.Length() == 0 {
node.SetVisited()
return nil
}
case *ast.JsonObjectNode:
isMapMeta := valueNode.GetMeta(OBJECT_FROM_MAP_META)
// map with no key value pair in struct field when omitempty set, omit it
if isMapMeta != nil && isMapMeta.(bool) {
if valueNode.Length() == 0 {
node.SetVisited()
return nil
}
}
default:
return nil
}
return nil
}
5 changes: 0 additions & 5 deletions astbuilder/golang/tokenprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ func (w *workingItem) SetMetaAndPlugins(node ast.JsonNode) {
}
}

if w.tagOptions.Omitempty {
// for omitEmpty, we will plug on the kvpair node directly, this will remove the push of k and v node
node.PrependPlugin(omitEmptyPlugin)
}

}

}
Expand Down

0 comments on commit 1907df2

Please sign in to comment.