无法解组不受支持的类型

When attempting to marshal XML,for example, take a struct such a this:

type Example struct{
    A int
    B int
    C func() int  // Unmarshallable
}

C is unmarshallable, and that's fine with me; it should be ignored. However, the most that I've found is the omitempty attribute which isn't valid here. Every attempt to marshal the struct fails.

What I've considered is the following:

  1. Making a brand new type for the function and attaching a MarshalXML method.
  2. Creating a new struct and copying each field manually into the new struct before marshalling.
  3. Attaching a MarshalXML method to the Example struct itself.
  4. Making C an unexported attribute and then setting it inside of its respective package.

All of these are less than ideal, but 4) seems to be the most appealing. I'm open to any other suggestions about marshalling the struct, while ignoring C.

Either of these is less than ideal because it leaves

Setting the "xml" struct field tag to - will prevent the field from being marshaled, as noted in the documentation:

The XML element for a struct contains marshaled elements for each of the exported fields of the struct, with these exceptions:

....

  • a field with tag "-" is omitted.
type Example struct{
    A int
    B int
    C func() int `xml:"-"`
}