Skip to content

Commit

Permalink
Merge pull request #128 from jhernand/accept_iterator_in_new_iterator
Browse files Browse the repository at this point in the history
Accept iterator in `helpers.NewIterator`
  • Loading branch information
jhernand authored Oct 14, 2021
2 parents d1d4aa0 + 2762442 commit 683bcbe
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/generators/golang/json_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (g *JSONSupportGenerator) generateHelpers() error {
g.buffer.Import("github.com/json-iterator/go", "")
g.buffer.Emit(`
// NewIterator creates a new JSON iterator that will read to the given source, which
// can be a slice of bytes, a string or a reader.
// can be a slice of bytes, a string, a reader or an existing iterator.
func NewIterator(source interface{}) (iterator *jsoniter.Iterator, err error) {
config := jsoniter.Config{}
api := config.Froze()
Expand All @@ -243,9 +243,11 @@ func (g *JSONSupportGenerator) generateHelpers() error {
iterator = jsoniter.ParseString(api, typed)
case io.Reader:
iterator = jsoniter.Parse(api, typed, 4096)
case *jsoniter.Iterator:
iterator = typed
default:
err = fmt.Errorf(
"expected slice of bytes, string or reader but got '%T'",
"expected slice of bytes, string, reader or iterator but got '%T'",
source,
)
}
Expand Down

0 comments on commit 683bcbe

Please sign in to comment.