Make LabelFieldSelector safe for JSON marshal and unmarshal
What would you like to be added/modified:
Add a clear JSON plan for LabelFieldSelector from your code, addressing the TODO.
Both Label and Field's real types keep data in private fields, so json.Marshal writes empty or wrong text and json.Unmarshal cannot pick the right type.
Why is this needed:
Without a fix any code that tries to save or send LabelFieldSelector or SelectorListener will lose the label and field rules. We need one agreed text form before anyone starts to save listeners.
There's two possible paths I can see here:
Keep fields, add custom JSON methods. Add MarshalJSON and UnmarshalJSON that store the two selectors as plain strings.
Store strings only. Change the struct to LabelSelector string and FieldSelector string with cached parsed values. JSON then just works, but every caller must change.
WDYT? I feel we can go for the former, if this decision is approved I'll make the PR.
Source: kubeedge/kubeedge