Giter Site home page Giter Site logo

spieker / active_model_serializers-jsonapi_embedded_records_deserializer Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 4.0 10 KB

Deserializing embedded JSONAPI records into ActiveRecord nested attributes (Not part of the JSONAPI spec yet!)

License: MIT License

Ruby 98.59% Shell 1.41%

active_model_serializers-jsonapi_embedded_records_deserializer's People

Contributors

jmarceli avatar spieker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

active_model_serializers-jsonapi_embedded_records_deserializer's Issues

Relationships data array

How about creating array of nested resources, e.g. items for order. Is it implemented?
If not which of structures below looks better to you:

{
  "data": {
    "type": "order",
    "attributes": {
      "title": "First order",
      "code": "123123123"
    },
    "relationships": {
      "items": [{
        "data": {
          "type": "item",
          "attributes": {
            "name": "T-shirt",
            "price": "12.50"
          }
        }
      }, {
        "data": {
          "type": "item",
          "attributes": {
            "name": "Sunglasses",
            "price": "50.00"
          }
        }
      }]
    }
  }
}

or (without data wrapper):

{
  "data": {
    "type": "order",
    "attributes": {
      "title": "First order",
      "code": "123123123"
    },
    "relationships": {
      "items": [{
          "type": "item",
          "attributes": {
            "name": "T-shirt",
            "price": "12.50"
          }
      }, {
          "type": "item",
          "attributes": {
            "name": "Sunglasses",
            "price": "50.00"
          }
      }]
    }
  }
}

Deep nesting support

Hi ,

Is there a way I can set this up to support deep nested objects?

Example;

{"data"=>
  {"id"=>"1",
   "attributes"=>
   {"attr1"=>true,
   "relationships"=>
    {"rel1"=>{"data"=>[{"attr1"=>"ok", "id"=>"1"}]},
     "rel2"=>
      {"data"=>
        [{"id"=>"1",
          "attributes"=>{"attr1"=>"true"},
          "relationships"=>
           {"rel2"=>{
            "rel3"=>
             {"data"=>
               [{"attributes"=>{"attr1"=>"10"},
                 "relationships"=>
                      ......

ActiveModelSerializers::Deserialization.jsonapi_parse(params, embedded: [:rel2])

The way this is now handled is deserializing only the top nested object

Optionally embed

Is it possible to optionally embed only if the resource contains an attributes key, otherwise fallback to the standard approach?

How do I use this with Rails + jsonapi-resources?

Can you provide an example how this should be used with a Rails + jsonapi-resources project?

I've included the gem in my Gemfile, but when I try to use ActiveModelSerializers::Deserialization.jsonapi_parse in my controllers, the Deserialization module is undefined.

I have a few questions:

  • Do I need to require this gem in my project somewhere? If so, where?
  • Is there a way to get jsonapi-resources to use this serializer by default, or do I need to manually call ActiveModelSerializers::Deserialization.jsonapi_parse in each of my controllers that need it?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.