Skip to content

UnmarshalJSON(v any) missing #29

Closed
@remster

Description

Is your feature request related to a problem? Please describe.
I have this function which has to return map[string][]interface{}:

func rulesets(ldClient *ld.LDClient, ldctx ldcontext.Context) (result map[string][]interface{}) {
	result = map[string][]interface{}{"foo": {"!=", "kind", "bar"}}
	ldval, _ := ldClient.JSONVariation("airspace_filter", ldctx, ldvalue.FromJSONMarshal(result))
	// I need LaunchDarkly to give me 'map[string][]interface{}' and not ldvalue. I shouldn't 
        // need to render the actual json so that I can unrender it back to 'map[string][]interface{}'
	if bytes, err := ldval.MarshalJSON(); err == nil {
		flagValue := map[string][]interface{}{}
		if err = json.Unmarshal(bytes, &flagValue); err == nil {
			result = flagValue
		}
	}
	return result
}

Describe the solution you'd like
I'd like this file to offer

// UnmarshalJSON stores itself in the value pointed to by v
func (v *Value) UnmarshalJSON(v any) error {
	bytes, err := v.MarshalJSON(); 
        if err == nil {
		return json.Unmarshal(bytes, v)
	}
        return err
}

Instead I see

// UnmarshalJSON parses a Value from JSON.
func (v *Value) UnmarshalJSON(data []byte) error {
	return jreader.UnmarshalJSONWithReader(data, v)
}

And its docu doesn't really say what it does - the grammar doesn't help.

Metadata

Assignees

No one assigned

    Labels

    waiting for feedbackIndicates LaunchDarkly is waiting for customer feedback before issue is closed due to staleness.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions