question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serializing a collection of objects with top level meta object

See original GitHub issue

JSON API allows adding a top level meta object: http://jsonapi.org/format/#document-meta

{
  "meta": {
    "copyright": "Copyright 2015 Example Corp.",
    "authors": [
      "Yehuda Katz",
      "Steve Klabnik",
      "Dan Gebhardt",
      "Tyler Kellen"
    ]
  },
  "data": {
    // ...
  }
}

Is there a way to do it in marshmallow-jsonapi? It seems like it’s only allows to have a meta in Resource Objects.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
swistakmcommented, Mar 20, 2018

@scottwernervt unfortunately this isn’t a solution to the problem, as meta field should be a top-level property so it should be:

{
    'data': {
        'type': 'user', 
        'id': 1,
    },
    'meta': {
        'custom':  'text'
    }
}

Instead of:

{
    'data': {
        'type': 'user', 
        'id': 1,
        'meta': {
            'custom':  'text'
        }
    }
}
0reactions
rgantcommented, May 2, 2018

I was playing with doing that, however I found that deserializing the data need a bunch of changes to _META_LOAD_FROM logic. It wasn’t designed with the idea of two Meta fields.

Might want to continue this conversation in #107

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to serialize top level objects with Json.NET as objects ...
To serialize and making use of the custom resolver you would: var serializer = new JsonSerializer { Formatting = Formatting.
Read more >
Serialization Guide - Json.NET
The Json.NET serializer can serialize a wide variety of .NET objects. This guide looks at how it works, first at a high level...
Read more >
Serializing Django objects
The whole collection of objects that is either serialized or deserialized is represented by a <django-objects> -tag which contains multiple <object> -elements.
Read more >
JSON serialization - Immutables
Generic parameters are supported when some upper level JSON document object specify actual type parameters, so nested document value objects that are ...
Read more >
Quickstart — marshmallow-jsonapi 0.24.0 documentation
Objects will be serialized to JSON API documents with primary data. ... field is used to serialize the meta object within a document's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found