// ToJSONCompatibleMap converts a Document-embedded struct into a JSON-compatible map,
// e.g. anything that cannot be jsonified will be ignored silently.
ToJSONCompatibleMap converts a Document-embedded struct into a JSON-compatible map,
e.g. anything that cannot be jsonified will be ignored silently.
// ToJSONCompatibleMap converts a Document - embedded struct into a JSON - compatible map // e . g . anything that cannot be jsonified will be ignored silently .
func ToJSONCompatibleMap(obj interface{}) (map[string]interface{}, error) {
	structValue := reflect.ValueOf(obj)
	if structValue.Kind() != reflect.Struct {
		return nil, ErrNotStruct
	}
	zero := reflect.Value{}
	if structValue.FieldByName("Document") == zero {
		return nil, ErrNotDocumentEmbedded
	}
	data, err := json.Marshal(obj)
	if err != nil {
		return nil, err
	}
	doc := map[string]interface{}{}
	err = json.Unmarshal(data, &doc)
	if err != nil {
		return nil, err
	}
	return doc, nil
}
func ToJSONCompatibleMap ( obj interface { } ) ( map [ string ] interface { } , error ) { structValue := reflect . ValueOf ( obj ) if structValue . Kind ( ) != reflect . Struct { return nil , ErrNotStruct } zero := reflect . Value { } if structValue . FieldByName ( " " ) == zero { return nil , ErrNotDocumentEmbedded } data , err := json . Marshal ( obj ) if err != nil { return nil , err } doc := map [ string ] interface { } { } err = json . Unmarshal ( data , & doc ) if err != nil { return nil , err } return doc , nil }
ToJSONCompatibleMap converts a Document-embedded struct into a JSON-compatible map,
e.g.
ToJSONCompatibleMap converts a Document - embedded struct into a JSON - compatible map e . g .