Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency Between .Wrap() and .New() Containers Causes Delete() to fail #141

Open
rflandau opened this issue Jun 6, 2024 · 0 comments

Comments

@rflandau
Copy link

rflandau commented Jun 6, 2024

There appears to be an under-the-hood inconsistency between a Wrap()-derived container and a New()-derived container. This causes both .Delete() and .DeleteP() to fail when called on Wrap()-derived containers.

Clock the following samples:

New

jObj := gabs.New()

jObj.Set(1, "A")
jObj.SetP(2, "B")

if err := jObj.Delete("B"); err != nil {
	panic(err)
}

fmt.Println(jObj.String())

This works as intended, returning {"A":1}.

Wrap

type t struct {
	A int
	B int
}

wrap := gabs.Wrap(t{A: 1, B: 2})

if err := wrap.Delete("B"); err != nil {
	panic(err)
}

fmt.Println(wrap)

This, however, panics, returning a 'not an object or array' error.


The difference occurs at gabs.go:471.
The New snippet has an actual map to operate on, containing map[string]interface {} {"A": 1, "B": 2} beneath the hood.
The Wrap container, however, is just data{A: 1, B: 2} and therefore fails the map type assertion.

I currently have a PR in the works to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant