8000 guidance on marshaling/unmarshaling · Issue #176 · dominikbraun/graph · GitHub
[go: up one dir, main page]

Skip to content

guidance on marshaling/unmarshaling #176

Open

Description

@richardhenwood

hi,

I would like to wrap this graph library in a api so I can interact with it from a web page. I have got a basic graph built with my custom vertex type. i have a Fiber route and provides access to my basic graph . When I attempt to marshal the graph to JSON in Fiber, I get an empty string.

To my inexperienced eye, it looks like I should use the Store interface. I should store the graph somewhere (like memory?) and then marshal/unmarshal the stored graph. Does that sound like the right/best approach?

thanks,
richard

Activity

  1. emilykmarx commented on May 28, 2026

    @emilykmarx

    I didn't see any built-in support in the library, but I had success with this -

    To marshal:

    • Get all edges (via Edges()) and vertices (via DFS() with a visit function that calls Vertex() and appends to an array)
    • Put the results in a struct
    • Marshal the struct - which for me required overriding MarshalJSON() on my node type

    To unmarshal:

    • Unmarshal into the same type of struct (similarly possibly overriding UnmarshalJSON())
    • Put the results into a new graph (via AddVertex() and AddEdge())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0