xson_builder 1.0.4

  • Readme
  • Changelog
  • Installing
  • 55

xson_builder can help you to easily generate dart json bean by json source. You can also change root class name and class name's suffix. Here are 2 ways to use this package.

  • generate programmatically with XsonBuilder().generateAndGetFileContent() or XsonBuilder().generateAndWriteFile().

  • generate dart json bean with @XsonBean via xson_annotation.

Example #

Generate programmatically #

  1. Create a instance of XsonBuilder.
  2. Get a json string via any way.
  3. Call method generateAndWriteFile(outputDir, outputFileName, json) can auto generate file, call method generateAndGetFileContent(outputFileName, json) can get file content.
import 'dart:io';

import 'package:xson_builder/xson_builder.dart';

XsonBuilder builder = XsonBuilder();

main() async {
  String content = File("./example/json/sample_json.json").readAsStringSync();
  builder.generateAndWriteFile("./example", "sample1.dart", content);
  1. Then sample1.dart will be generated.
  2. execute build_runner command pub run build_runner build.
  3. Then sample1.g.dart will be generated.

Generate by build_runner

  1. Depends package xson_annotation.
  2. Given a dart file sample3.dart with a Sample3 class annotated with @XsonBean().
  3. Given @XsonBean() a json source way, raw json(jsonContent:) or json file path(jsonFilePath:). You can only choose one way to generate.
  4. If you use raw json way, you class will be like this:
import 'package:xson_annotation/xson_annotation.dart';

const _json = """
  "name": "apple",
  "price": 60.5,
  "color": "yellow"

@XsonBean(jsonContent: _json)
class Sample4 {}
  1. If you use json file path way, you class will be like this:
import 'package:xson_annotation/xson_annotation.dart';

@XsonBean(jsonFilePath: "./example/json/sample_json.json")
class Sample3 {}
  1. Execute build_runner command pub run build_runner build.
  2. Then sample1.xson.dart and sample1.xson.g.dart will be generated.

1.0.0 #

  • Initial version, created by Stagehand

1.0.1 #

  • support bean's key renamed.

1.0.2 #

  • XFile recodes with version 1.1.0

1.0.3 #

  • support json content comments ignores

1.0.4 #

  • fix _fromJsonXXX for null input

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  xson_builder: ^1.0.4

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:xson_builder/xson_builder.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health issues and suggestions

Document public APIs. (-1 points)

9 out of 9 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/builder.dart.

Run dartfmt to format lib/builder.dart.

Format lib/src/ancestor_info.dart.

Run dartfmt to format lib/src/ancestor_info.dart.

Format lib/src/xson_bean_generator.dart.

Run dartfmt to format lib/src/xson_bean_generator.dart.

Format lib/src/xson_builder_core.dart.

Run dartfmt to format lib/src/xson_builder_core.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (analyzer).

The package description is too short. (-7 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and xson_builder.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
analyzer >=0.37.1 <0.39.0 0.38.5 0.39.4
build ^1.2.1 1.2.2
dartpoet ^1.0.5+4 1.0.6+3
named_mode ^1.0.2+1 1.0.2+1
path ^1.6.0 1.6.4
source_gen ^0.9.4+5 0.9.4+6 0.9.4+7
type_translator ^1.0.1+1 1.0.3
xfile ^1.1.0 1.1.0
xson ^1.0.4 1.0.4
xson_annotation ^1.0.2+1 1.0.2+1
Transitive dependencies
args 1.5.2
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.3.3
front_end 0.1.27 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
kernel 0.3.27 0.3.29
logging 0.11.4
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
pub_semver 1.4.2
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
type_token 1.0.4
typed_data 1.1.6
watcher 0.9.7+13
yaml 2.2.0
Dev dependencies
build_runner ^1.6.7
build_test ^0.10.3
json_annotation ^3.0.0
json_serializable ^3.2.2
pedantic ^1.7.0 1.9.0
test ^1.6.0