mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Adding JSON example. (#1)
This commit is contained in:
25
jsonexample/lib/built_value/built_value_serializers.dart
Normal file
25
jsonexample/lib/built_value/built_value_serializers.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
library serializers;
|
||||
|
||||
import 'package:built_collection/built_collection.dart';
|
||||
import 'package:built_value/serializer.dart';
|
||||
import 'package:built_value/standard_json_plugin.dart';
|
||||
import 'package:jsonexample/built_value/built_complex_object.dart';
|
||||
import 'package:jsonexample/built_value/built_simple_object.dart';
|
||||
|
||||
part 'built_value_serializers.g.dart';
|
||||
|
||||
@SerializersFor(const [
|
||||
BuiltSimpleObject,
|
||||
BuiltComplexObject,
|
||||
])
|
||||
|
||||
// By default, `built_value` serialization uses lists and is not compatible
|
||||
// with other JSON formats. If you'd like to serialize data using a map-based
|
||||
// JSON approach (which is what you'll find in the json_strings.dart file in
|
||||
// this project), you can add the StandardJsonPlugin as you see here.
|
||||
final Serializers serializers =
|
||||
(_$serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build();
|
||||
Reference in New Issue
Block a user