Giter Site home page Giter Site logo

infinum / flutter-plugins-japx Goto Github PK

View Code? Open in Web Editor NEW
24.0 9.0 15.0 220 KB

JSON API parser for Flutter

Home Page: https://pub.dev/packages/japx

License: MIT License

Kotlin 0.63% Swift 1.98% Objective-C 0.19% Dart 97.20%
json-api json decoder encoder parser open-source flutter

flutter-plugins-japx's Issues

Array relationships in included relationships are set to null if they are not present

Array relationships (one-many) that are part of the "included" field have their items set as null when they themselves are not included in the server response. For example:

{
    {
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!",
      "body": "The shortest article. Ever.",
      "created": "2015-05-22T14:56:29.000Z",
      "updated": "2015-05-22T14:56:28.000Z"
    },
    "relationships": {
      "author": {
        "data": {"id": "42", "type": "people"}
      }
    }
  },
  "included": [
    {
      "type": "people",
      "id": "42",
      "attributes": {
        "name": "John",
        "age": 80,
        "gender": "male"
      },
      "relationships": {
        "article": {
          "data": {"id": "1", "type": "articles"}
        },
        "categories" : {
          "data" : [
            {"id": "1", "type": "categories"}
          ]
        }
      }
    }
  ]
}

Here relationships.article will be correctly parsed and shown, but categories.data will be set to a array with all its items in null (it won't even be an empty array, breaking applications on some server responses).

The expected output is:

{
  "data": {
    "type": "articles",
    "id": "1",
    "title": "JSON API paints my bikeshed!",
    "body": "The shortest article. Ever.",
    "created": "2015-05-22T14:56:29.000Z",
    "updated": "2015-05-22T14:56:28.000Z",
    "author": {
      "type": "people",
      "id": "42",
      ...
      "categories": [
        {
          "type": "categories",
          "id": "1"
        }
      ],
      "article": { ... }
    }
  }
}

The actual output is

{
  "data": {
    "type": "articles",
    "id": "1",
    "title": "JSON API paints my bikeshed!",
    "body": "The shortest article. Ever.",
    "created": "2015-05-22T14:56:29.000Z",
    "updated": "2015-05-22T14:56:28.000Z",
    "author": {
      "type": "people",
      "id": "42",
      ...
      "categories": [
        null
      ],
      "article": { ... }
    }
  }
}

This is fixed in #19

Nested JSON is not getting parsed

The mentioned json is not getting parsed using the package but deserialize-json package in ReactJS is able to parse it
Please look into this and help me get a solution

{
"data": [
{
"id": "1090",
"type": "user",
"attributes": {
"display_name": "Ram Singh",
"username": "ram_singh",
"is_followed": true,
"is_requested": false,
"dp_url": null,
"dp_thumbnail": null,
"can_accept": null
},
"relationships": {
"user_profile": {
"data": {
"id": "716",
"type": "user_profile"
}
},
"generated_feeds": {
"data": [
{
"id": "19421",
"type": "story_feed"
}
]
}
}
}
],
"included": [
{
"id": "716",
"type": "user_profile",
"attributes": {
"privacy_level": "privat3",
"first_name": null,
"last_name": null,
"is_verified": false,
"market_view": "neutral",
"bio": "-"
}
},
{
"id": "3390",
"type": "attachment",
"attributes": {
"name": "media_files",
"record_type": "Story",
"record_id": 1139,
"blob": {
"id": 3390,
"key": "dasdasd",
"filename": "photo-sadads-d68292c34b19.jpeg",
"content_type": "image/jpeg",
"metadata": {
"identified": true,
"width": 801,
"height": 1200,
"analyzed": true
},
"byte_size": 125574,
"checksum": "asdsa==",
"created_at": "2023-09-29T13:54:03.110+05:30",
"service_name": "amazon",
"attachable_sgid": "XXXXX"
},
"key": "mgx4yrm7x9senrj7tjst0jh35rfi",
"file_path": "XXXXXXX",
"file_type": "image/jpeg"
}
},
{
"id": "3391",
"type": "attachment",
"attributes": {
"name": "media_files",
"record_type": "Story",
"record_id": 1139,
"blob": {
"id": 3391,
"key": "XXXXX",
"filename": "IMG_20230908_155020.jpg",
"content_type": "image/jpeg",
"metadata": {
"identified": true,
"width": 900,
"height": 1200,
"analyzed": true
},
"byte_size": 19478,
"checksum": "XXXX==",
"created_at": "2023-09-29T13:54:03.119+05:30",
"service_name": "amazon",
"attachable_sgid": "XXXX"
},
"key": "q2d4vslbodymdeyn94jfxufrcht4",
"file_path": "/XXXX",
"file_type": "image/jpeg"
}
},
{
"id": "3392",
"type": "attachment",
"attributes": {
"name": "media_files",
"record_type": "Story",
"record_id": 1139,
"blob": {
"id": 3392,
"key": "XXX",
"filename": "pexels-pixabay-268533.jpg",
"content_type": "image/jpeg",
"metadata": {
"identified": true,
"width": 1200,
"height": 799,
"analyzed": true
},
"byte_size": 71428,
"checksum": "CCCC/QfkRHGrwA==",
"created_at": "2023-09-29T13:54:03.125+05:30",
"service_name": "amazon",
"attachable_sgid": "CcCc--2a06d6e5ddd495cd4069b78fc7c50ba5afedda23"
},
"key": "pxggs6sovg9ztw84t7lokf48yyys",
"file_path": "/rpexels-pixabay-268533.jpg",
"file_type": "image/jpeg"
}
},
{
"id": "1090",
"type": "user",
"attributes": {
"display_name": "Mritunjay Singh",
"username": "mritunjay_singh",
"is_followed": true,
"is_requested": false,
"dp_url": null,
"dp_thumbnail": null,
"can_accept": null
},
"relationships": {
"user_profile": {
"data": {
"id": "716",
"type": "user_profile"
}
}
}
},
{
"id": "1139",
"type": "story",
"attributes": {
"message": null,
"visibility": "followers_visible",
"created_at": "2023-09-29T13:54:03.102+05:30",
"updated_at": "2023-09-29T13:54:03.130+05:30",
"meta_info": {
"text_color": "#000aaa",
"bg_color": "#000fff"
},
"likes_count": null,
"widgets_data": null,
"is_liked": false,
"is_deleted": false,
"views_count": 10
},
"relationships": {
"user": {
"data": {
"id": "1090",
"type": "user"
}
},
"poll": {
"data": null
},
"attachments": {
"data": [
{
"id": "3390",
"type": "attachment"
},
{
"id": "3391",
"type": "attachment"
},
{
"id": "3392",
"type": "attachment"
}
]
},
"media_files": {
"data": [
{
"id": "3390",
"type": "media_files"
},
{
"id": "3391",
"type": "media_files"
},
{
"id": "3392",
"type": "media_files"
}
]
},
"tagged_users": {
"data": []
},
"tagged_topics": {
"data": []
},
"tagged_instruments": {
"data": []
}
}
},
{
"id": "593",
"type": "user",
"attributes": {
"display_name": "Rohit Agarwal",
"username": "rohit_agarwal_ce22",
"is_followed": false,
"is_requested": false,
"dp_url": null,
"dp_thumbnail": null,
"can_accept": null
},
"relationships": {
"user_profile": {
"data": {
"id": "444",
"type": "user_profile"
}
}
}
},
{
"id": "19421",
"type": "story_feed",
"attributes": {
"read_at": null,
"viewer_id": 593,
"created_at": "2023-09-29T13:54:03.417+05:30",
"updated_at": "2023-09-29T13:54:03.417+05:30"
},
"relationships": {
"viewer": {
"data": {
"id": "593",
"type": "user"
}
},
"story": {
"data": {
"id": "1139",
"type": "story"
}
}
}
}
]
}

The above JSON does not give all the referenced or linked parts only links the user profile, but if we mention the "generated_feeds" in the includedList it links the list of generated_feeds but again it does not links user,story,attachements to it

Kindly if anyone has a solution then let me know
using the latest version of the package. japx: ^2.1.0 with Flutter version 3.13.x

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.