Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonahwilliams/typewriter
https://github.com/jonahwilliams/typewriter
dart deserialization json serialization xml
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/jonahwilliams/typewriter
- Owner: jonahwilliams
- License: bsd-3-clause
- Created: 2017-02-15T04:28:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-14T08:10:59.000Z (almost 8 years ago)
- Last Synced: 2024-10-18T23:32:00.131Z (4 months ago)
- Topics: dart, deserialization, json, serialization, xml
- Language: Dart
- Size: 59.6 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Typewriter [![Build Status](https://travis-ci.org/jonahwilliams/typewriter.svg?branch=master)](https://travis-ci.org/jonahwilliams/typewriter)
Typewritter is a Dart library for generating [codecs](https://www.dartlang.org/articles/libraries/converters-and-codecs), encoder/decoder pairs for serialization. Serialization code is repetitive and time consuming to write. Instead of using reflection/mirrors, Typewriter enables developers to generate configurable codecs automatically from Dart source code.
The supported target languages are
* JSON
* XML (partial)
* Yaml (planned)This library is currently under active development and is not stable enough for non-experimental use.
## Example Usage
Typewriter annotations configure the behavior of the generated codecs. For example, the following Class uses a `JsonKey` annotation, which changes the name of the field on the resulting JSON.```dart
@deriveJson()
class Person {
int age;
@jsonProperty('birth_day')
DateTime birthDay;
String name;
Cat myCat;
}@deriveJson()
class Cat {
String name;
}
```
An instance of this class serialized to JSON would look something like the following.```json
{ "age": 25, "birth_day": "some-long-iso-string", "name": "Jonah", "myCat": {"name": "Mike Hat"}}
```Xml annotations support configuring the names of elements and child elements with `XmlElement`. The annotation `XmlAttribute` allows developers to place annotations on any of the elements in the class.
```dart
@deriveXml()
class ApiResponse {
@xmlElement('name-list', 'name')
List names;
@xmlAttribute('name-length', element: 'name-list')
int length;
}
```
The following is an instance of `ApiResponse` serialized to XML. Typewriter also handles the xml header.
```xml
Peter Parker
Bruce Wayne
Snoop Dogg
```