An open API service indexing awesome lists of open source software.

https://github.com/hokamc/otter_json

A compile safe JSON serialization in generic way
https://github.com/hokamc/otter_json

compile-safe dart flutter json serialization

Last synced: 2 months ago
JSON representation

A compile safe JSON serialization in generic way

Awesome Lists containing this project

README

          


Otter JSON


Otter JSON

[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)]()
[![Status](https://img.shields.io/badge/status-active-success.svg)]()


JSON serialization with code generation.

## Table of Contents

- [Table of Contents](#table-of-contents)
- [Why use it](#why-use-it)
- [How to](#how-to)
- [Todo](#todo)
- [Link](#link)
- [Authors](#authors)

## Why use it

Do you suffer from json_serializable? All generated code and 'part' make your source code messy. With Otter JSON, keep everything simple and clean.

## Features

- Generated code and source code are separated
- Easy to register new serializer
- Support all primitives
- Support flutter common class
- Support List, Set, Map
- Support nested object

## How to

- dependencies
```yaml
dependencies:
otter_json:

dev_dependencies:
build_runner:
otter_json_generator:
```

- annotate
```dart
@JSON
class Person {
String firstName;
String lastName;
}
```

- generate
```shell script
flutter pub run build_runner build
```

- register
```dart
Otter.module(GeneratedJsonModule());
```

- toJson, fromJson
```dart
Map map = Otter.toJson(Person());
Person person = Otter.fromJson({});
```

- custom serializer
```dart
class ColorSerializer implements JsonSerializer {
@override
Color decode(int output) {
return Color(output);
}

@override
int encode(Color input) {
return input.value;
}
}

Otter.serializer(ColorSerializer());
```

## Todo

## Link

[otter_json](https://pub.dev/packages/otter_json)

[otter_json_generator](https://pub.dev/packages/otter_json_generator)

## Authors

- [@hokamc](https://github.com/hokamc)