Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export clearIncluded #188

Open
vdvibhu20 opened this issue Feb 15, 2020 · 1 comment
Open

Export clearIncluded #188

vdvibhu20 opened this issue Feb 15, 2020 · 1 comment

Comments

@vdvibhu20
Copy link

vdvibhu20 commented Feb 15, 2020

I want to send meta without using Metable interface.

I use a serializer wrapper as mentioned below. but right now p.clearIncluded() is undefined as it is not exported.

func SerializeWithMeta(w io.Writer, models interface{}, includeModels bool, meta jsonapi.Meta) (err error) {
	p, err := jsonapi.Marshal(models)
	if err != nil {
		return
	}

	if !includeModels {
		p.clearIncluded()
	}

	payloadOne, ok := p.(*jsonapi.OnePayload)
	if ok {
		payloadOne.Meta = &meta
		return json.NewEncoder(w).Encode(payloadOne)
	}

	payloadMany, ok := p.(*jsonapi.ManyPayload)
	payloadMany.Meta = &meta
	return json.NewEncoder(w).Encode(payloadMany)
}
@vdvibhu20 vdvibhu20 changed the title add clearIncluded to exported methods Support clearIncluded to exported methods Feb 18, 2020
@vdvibhu20 vdvibhu20 changed the title Support clearIncluded to exported methods Export clearIncluded Feb 18, 2020
@vdvibhu20
Copy link
Author

@aren55555

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant