Skip to content

Commit 0f8db57

Browse files
committed
Repo boilerplate
Mostly copied from the source_gen repo - Initial README with example - LICENSE, AUTHORS, CONTRIBUTING - .gitignore
0 parents  commit 0f8db57

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.dart_tool
2+
.packages
3+
.pub
4+
packages
5+
pubspec.lock

Diff for: AUTHORS

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Below is a list of people and organizations that have contributed
2+
# to the project. Names should be added to the list like so:
3+
#
4+
# Name/Organization <email address>
5+
6+
Google Inc.

Diff for: CONTRIBUTING.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Want to contribute? Great! First, read this page (including the small print at
2+
the end).
3+
4+
### Before you contribute
5+
Before we can use your code, you must sign the
6+
[Google Individual Contributor License Agreement](https://cla.developers.google.com/about/google-individual)
7+
(CLA), which you can do online. The CLA is necessary mainly because you own the
8+
copyright to your changes, even after your contribution becomes part of our
9+
codebase, so we need your permission to use and distribute your code. We also
10+
need to be sure of various other things—for instance that you'll tell us if you
11+
know that your code infringes on other people's patents. You don't have to sign
12+
the CLA until after you've submitted your code for review and a member has
13+
approved it, but you must do it before we can put your code into our codebase.
14+
15+
Before you start working on a larger contribution, you should get in touch with
16+
us first through the issue tracker with your idea so that we can help out and
17+
possibly guide you. Coordinating up front makes it much easier to avoid
18+
frustration later on.
19+
20+
### Code reviews
21+
All submissions, including submissions by project members, require review.
22+
23+
### File headers
24+
All files in the project must start with the following header.
25+
26+
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
27+
// for details. All rights reserved. Use of this source code is governed by a
28+
// BSD-style license that can be found in the LICENSE file.
29+
30+
### The small print
31+
Contributions made by corporations are covered by a different agreement than the
32+
one above, the
33+
[Software Grant and Corporate Contributor License Agreement](https://developers.google.com/open-source/cla/corporate).

Diff for: LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright 2017, the Dart project authors. All rights reserved.
2+
Redistribution and use in source and binary forms, with or without
3+
modification, are permitted provided that the following conditions are
4+
met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google Inc. nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Diff for: README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# json_serializable
2+
3+
## Overview
4+
5+
`json_serializable` provides `source_gen` `Generator`s which generate code to
6+
make it simple to serialize to and from JSON.
7+
8+
## Example
9+
10+
Given a library `example.dart` with an `Person` class annotated with
11+
`@JsonSerializable`:
12+
13+
```dart
14+
library source_gen.example;
15+
16+
import 'package:source_gen/generators/json_serializable.dart';
17+
part 'example.g.dart';
18+
19+
@JsonSerializable()
20+
class Person extends Object with _$PersonSerializerMixin {
21+
final String firstName, middleName, lastName;
22+
23+
@JsonKey('date-of-birth')
24+
final DateTime dateOfBirth;
25+
26+
Person(this.firstName, this.lastName, {this.middleName, this.dateOfBirth});
27+
28+
factory Person.fromJson(json) => _$PersonFromJson(json);
29+
}
30+
```
31+
32+
`source_gen` creates the corresponding part `example.g.dart`:
33+
34+
```dart
35+
part of source_gen.example;
36+
37+
Person _$PersonFromJson(Map json) => new Person(
38+
json['firstName'], json['lastName'],
39+
middleName: json['middleName'],
40+
dateOfBirth: json['date-of-birth'] == null
41+
? null
42+
: DateTime.parse(json['date-of-birth']));
43+
44+
abstract class _$PersonSerializerMixin {
45+
String get firstName;
46+
String get middleName;
47+
String get lastName;
48+
DateTime get dateOfBirth;
49+
Map<String, dynamic> toJson() => <String, dynamic>{
50+
'firstName': firstName,
51+
'middleName': middleName,
52+
'lastName': lastName,
53+
'date-of-birth': dateOfBirth?.toIso8601String(),
54+
};
55+
}
56+
```

0 commit comments

Comments
 (0)