dart_jsona 0.0.1 copy "dart_jsona: ^0.0.1" to clipboard
dart_jsona: ^0.0.1 copied to clipboard

outdated

Deserialize or serialize JsonApi document

example/dart_jsona_example.dart

import 'package:dart_jsona/dart_jsona.dart';

void main() {
  Jsona jsona = new Jsona();

  Map<String, dynamic> body = {
    'data': {
      'type': 'town',
      'id': '123',
      'attributes': {
        'name': 'Barcelona',
      },
      'relationships': {
        'country': {
          'data': {
            'type': 'country',
            'id': '32',
          }
        }
      }
    },
    'included': [{
      'type': 'country',
      'id': '32',
      'attributes': {
        'name': 'Spain',
      }
    }]
  };

  final dynamic town = jsona.deserialize(body);

  print(town);
  /**
   * {
   *  type: town,
   *  id: 123,
   *  name: Barcelona,
   *  country: {
   *    type: country,
   *    id: 32, name: Spain
   *  },
   *  relationshipNames: [country]}
   */


  Map<String, Object> jsonBody = jsona.serialize(stuff: town, includeNames: ['country']);

  print(jsonBody);
  /**
   * {
   *   data: {
   *     id: 123,
   *     type: town,
   *     attributes: {
   *       name: Barcelona
   *     },
   *     relationships: {
   *       country: {
   *         data: {
   *           id: 32, type: country
   *         }
   *       }
   *     }
   *   },
   *   included: [{
   *     id: 32,
   *     type: country,
   *     attributes: {
   *       name: Spain
   *     }
   *   }]
   * }
   */
}
1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Deserialize or serialize JsonApi document

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on dart_jsona