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

Unable to Json.Marshal an Envelope object #146

Open
jnury opened this issue Jan 22, 2020 · 3 comments
Open

Unable to Json.Marshal an Envelope object #146

jnury opened this issue Jan 22, 2020 · 3 comments

Comments

@jnury
Copy link

jnury commented Jan 22, 2020

What I did: json.Marshal(envelope)

What I expected: convert an Envelope object into Json

What I got: a stack overflow when envelope contains at least one part

Release or branch I am using: master

Please find attached a file to reproduce. As I understand the problem, there is an infinite loop while walking the Envelope object as we can go to Envelope.Root.FirstChild.Parent.FirstChild.Parent en so one.

Would it be possible to create a func (e *Envelope) ToJson() (string, error) function ?
Or instruct Json.Marshal to not walk thru the Parent property ?

Thanks for your help

enmime_json_marshal.go.txt

@jhillyerd
Copy link
Owner

I think this is worth fixing, thanks for letting us know.

@jhillyerd jhillyerd added this to the v1.0.0 milestone Dec 18, 2020
@jawr
Copy link
Contributor

jawr commented Apr 4, 2021

How do you envision this working @jhillyerd implementing the encoding/json MarshallJSON interface, or having it as a method function as suggested above?

Also what format do we want? Started putting this together as a jumping off point:

HEADER{
    "key": "",
    "value": ""
}

PART{
    "boundary": "",
    "headers": HEADER[],
    "content": ""
}

ENVELOPE{
    "headers": HEADER[],
    "text": "",
    "html": "",
    "attachments": PART[],
    "inlines": PART[]
}

@jhillyerd
Copy link
Owner

jhillyerd commented Apr 4, 2021

There would be a lot of duplicated information if were to encode both the envelope, and the entire part tree to JSON. I suspect most users would just want the envelope content.

Implementing the MarshallJSON interface would be the path of least surprise, and should let Envelope be embedded into other structs for serialization. Given that, I'd like to match the default attribute naming of Go as much as possible, even though I don't love the way Go does it. :)

Not sure if useful, but this is what one of my other projects outputs when serializing an email parsed by enmime: https://github.com/inbucket/inbucket/wiki/REST-GET-message

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

No branches or pull requests

3 participants