{"id":19593928,"url":"https://github.com/edsonbonfim/json_serializer","last_synced_at":"2025-10-06T18:18:09.819Z","repository":{"id":194737354,"uuid":"691788635","full_name":"edsonbonfim/json_serializer","owner":"edsonbonfim","description":"Automatically convert JSON to dart objects in runtime without code generation.","archived":false,"fork":false,"pushed_at":"2023-11-03T14:20:46.000Z","size":39,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-29T22:51:13.160Z","etag":null,"topics":["dart","flutter","json","json-serializer","serializer"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/json_serializer","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edsonbonfim.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-14T22:31:20.000Z","updated_at":"2024-11-10T13:37:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"8cc85983-b145-418e-a24e-e2d399c04ac3","html_url":"https://github.com/edsonbonfim/json_serializer","commit_stats":null,"previous_names":["edsonbonfim/json_serializer"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edsonbonfim%2Fjson_serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edsonbonfim%2Fjson_serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edsonbonfim%2Fjson_serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edsonbonfim%2Fjson_serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edsonbonfim","download_url":"https://codeload.github.com/edsonbonfim/json_serializer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250394373,"owners_count":21423360,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","json","json-serializer","serializer"],"created_at":"2024-11-11T08:41:46.970Z","updated_at":"2025-10-06T18:18:04.774Z","avatar_url":"https://github.com/edsonbonfim.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Serializer\n\nA versatile Dart package for effortless JSON serialization and deserialization without the need for\ncode generation or reflection.\n\n---\n\n## Getting Started\n\nTo get started, simply import the `json_serializer` package:\n\n```dart\nimport 'package:json_serializer/json_serializer.dart';\n```\n\n### JSON Deserialization\n\nSuppose you have the following Dart classes:\n\n```dart\nenum Gender { male, female }\n\nclass Person {\n  final String name;\n  final Gender gender;\n  final Address address;\n\n  Person({required this.name, required this.gender, required this.address});\n}\n\nclass Address {\n  final String street;\n  final String city;\n\n  Address({required this.street, required this.city});\n}\n```\n\nYou can deserialize JSON data into these classes as follows:\n\n```dart\nmain() {\n  // Define user-defined types for successful deserialization\n  JsonSerializer.options = JsonSerializerOptions(types: [\n    UserType\u003cPerson\u003e(Person.new),\n    UserType\u003cAddress\u003e(Address.new),\n    EnumType\u003cGender\u003e(Gender.values),\n  ]);\n\n  var json =\n      '{\"name\":\"John\",\"gender\":\"male\",\"address\":{\"street\":\"123 Main St\",\"city\":\"Sampletown\"}}';\n\n  var person = deserialize\u003cPerson\u003e(json);\n\n  print('Name: ${person.name}');\n  print('Gender: ${person.gender.name}');\n  print('Street: ${person.address.street}');\n  print('City: ${person.address.city}');\n}\n```\n\nNote that you should use `JsonSerializerOptions` to register all of your referenced classes or\nenums.\n\n### Serialization\n\nTo serialize, all your referenced classes should implement the `Serializable` interface, which\nrequires an implementation of `toMap`, a simple map of key and value properties.\n\n```dart\nclass Person implements Serializable {\n  final String name;\n  final Gender gender;\n  final Address address;\n\n  Person({required this.name, required this.gender, required this.address});\n\n  @override\n  Map\u003cString, dynamic\u003e toMap() {\n    return {'name': name, 'gender': gender, 'address': address};\n  }\n}\n\nclass Address implements Serializable {\n  final String street;\n  final String city;\n\n  Address({required this.street, required this.city});\n\n  @override\n  Map\u003cString, dynamic\u003e toMap() {\n    return {'street': street, 'city': city};\n  }\n}\n```\n\nYou can then easily serialize objects:\n\n```dart\nprint(serialize(person));\n// {\"name\":\"John\",\"gender\":\"male\",\"address\":{\"street\":\"123 Main St\",\"city\":\"Sampletown\"}}\n```\n\n## License\n\nThis library is licensed under the [BSD 3-Clause License](LICENSE). Feel free to use it and\ncontribute to its development.\n\n---\n\nMade with ❤️ by Edson Bonfim","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedsonbonfim%2Fjson_serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedsonbonfim%2Fjson_serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedsonbonfim%2Fjson_serializer/lists"}