GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - eitanliu/json_reflectable: This package allows programmers to annotate Dart objects for reflective invocation of the fromJson and toJson methods.

BranchesTags
Open more actions menu

Latest commit

 

History

4 Commits
4 Commits

Folders and files

NameName
Last commit message
Last commit date
.idea
.idea
 
 
example
example
 
 
lib
lib
 
 
test
test
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
analysis_options.yaml
analysis_options.yaml
 
 
pubspec.yaml
pubspec.yaml
 
 

Repository files navigation

This package allows programmers to annotate Dart objects for reflective invocation of the fromJson and toJson methods.

Features

This package allows programmers to annotate Dart objects for reflective invocation of the fromJson and toJson methods.

Getting started

Add into your pubspec.yaml

dependencies:
  json_reflectable: ^1.0.0

Or run command in Terminal

flutter pub add json_reflectable

Usage

Add into your main.dart

import 'main.reflectable.dart';

void main() {
  initializeReflectable();
  //...
}

Add @jsonReflector to the classes that require reflection

@jsonReflector
@JsonSerializable()
class TextEntity {
  double float;
  String string;

  TextEntity(this.float, this.string);

  factory TextEntity.fromJson(Map<String, dynamic> json) =>
      _$TextEntityEntityFromJson(json);

  Map<String, dynamic> toJson() => _$TextEntityEntityToJson(this);
}

Using instance mirror

final testJson = jsonDecode('''
{
  "float": 1.0,
  "string": "str"
}
''');
TextEntity instance = TextEntity.fromJson(testJson);
print(jsonReflector.toJson(instance));

Using class mirror

TextEntity instance = jsonReflector.formJson<TextEntity>(testJson);
print(instance.toJson());

Using iterable

final iterable = Iterable.generate(3, (index) => jsonMap);
final list = jsonReflector.formIterable<Text01Entity>(iterable).toList();
print("list ${list.runtimeType}");
print(jsonEncode(list));

Additional information

where to find more information

how to contribute to the package

how to file issues

About

This package allows programmers to annotate Dart objects for reflective invocation of the fromJson and toJson methods.

pub.dev/packages/json_reflectable

Resources

Readme
Apache-2.0 license
Activity

Stars

2 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.