I saw some code where there is a temporary type called *noMethod* created 
before performing custom marshaling.

What is the purpose of doing this?  

type T struct {
 A int
 C string
}


func (t T) MarshalText() (text []byte, err error) {
 type noMethod T
 return json.Marshal(noMethod(t))
}


func (t *T) UnmarshalText(text []byte) error {
 type noMethod T
 return json.Unmarshal(text, (*noMethod)(t))
}


func (t T) MarshalJSON() (text []byte, err error) {
 type noMethod T
 return json.Marshal(noMethod(t))
}


func (t *T) UnmarshalJSON(text []byte) error {
 type noMethod T
 return json.Unmarshal(text, (*noMethod)(t))
}





https://play.golang.org/p/e8cZfkU1uvE 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cacde93e-6b27-49e7-962f-e755f62ed442%40googlegroups.com.

Reply via email to