Skip to content

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

@rflandau

Description

@rflandau

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions