Skip to content

Support for pointer to slice and pointer value for script #210

@edward-frankieone

Description

@edward-frankieone

Hi,

Is there any plan to support pointer to slice for struct use case?

For example:

func TestPointerSlice(t *testing.T) {
	type Child struct {
		Current *bool
		Value   *string
	}
	type Parent struct {
		Children *[]Child
	}
	data := Parent{
		Children: &[]Child{
			{Current: pointer(true), Value: pointer("a")},
			{Current: pointer(false), Value: pointer("b")},
		},
	}
	expr := jp.MustParseString(".children[?(@.current!=false)].value")
	results := expr.Get(data)
	got := oj.JSON(results)
	if `["a"]` != got {
		t.Errorf(`Expected ["a"], got %s`, got)
	}
}

func pointer[T any](s T) *T {
	return &s
}

If the test is run:

    example_test.go:177: Expected ["a"], got []

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