Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Refactor missing exception and prepare for 1.0.0-alpha+3
Browse files Browse the repository at this point in the history
  • Loading branch information
eredo committed Sep 20, 2018
1 parent 3a4e11f commit babf096
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion changelog.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 1.0.0-alpha+3
## 1.0.0-alpha+3 (09/20/2018)

- Add support for final properties
- Add support to skip private properties
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![Build Status](https://travis-ci.org/eredo/dartson.svg?branch=master)](https://travis-ci.org/eredo/dartson)
[![Coverage Status](https://coveralls.io/repos/github/eredo/dartson/badge.svg)](https://coveralls.io/github/eredo/dartson)

**Dartson 1.0.0 is currently in alpha. The public API might be subject to change.**
**Dartson 1.0.0 is currently in alpha. The public API might be subject to change. For further details of
potential breaks and a roadmap take a look at [project 1.0.0](https://github.com/eredo/dartson/projects/1).**

Dartson is a dart library which converts Dart Objects into their JSON representation. It helps you keep your code clean
of `fromJSON` and `toJSON` functions by providing a builder which generates the serialization methods.
Expand Down
18 changes: 18 additions & 0 deletions lib/src/exceptions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:analyzer/dart/element/element.dart';

/// Thrown when encode or decode method is called with a dart object that
/// is not available within the entities list of the serializer.
class UnknownEntityException implements Exception {
Expand Down Expand Up @@ -38,3 +40,19 @@ class MissingDecodeMethodException implements Exception {
'TypeTransformers: $type. Please make sure to implement TypeTransformer '
'and overwrite the interface methods.';
}

/// Thrown by the generator in case a not optional argument within an entity
/// constructor is marked as ignored and therefore the generator cannot fill in
/// a value.
class NotOptionalArgumentIgnoredException implements Exception {
final Element field;
final ClassElement type;

NotOptionalArgumentIgnoredException(this.field, this.type);

@override
String toString() =>
'NotOptionalArgumentIgnoredException: The field ${field.name} in '
'${type.name} is annotated with @Property(ignore:true) but is a not '
'optional argument of the constructor.';
}
4 changes: 2 additions & 2 deletions lib/src/generator/entity_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:json_serializable/src/type_helpers/iterable_helper.dart';
import 'package:json_serializable/src/type_helpers/map_helper.dart';

import '../annotations.dart';
import '../exceptions.dart';
import 'entity_type_helper.dart';
import 'field_context.dart';
import 'identifier.dart';
Expand Down Expand Up @@ -100,8 +101,7 @@ class EntityGenerator {
}

if (fieldProperty.ignore && field.isNotOptional) {
// TODO: Throw proper error.
throw 'NotOptional marked as ignored';
throw NotOptionalArgumentIgnoredException(field, _element);
}

if (fieldProperty.ignore) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dartson
version: 1.0.0-alpha+2
version: 1.0.0-alpha+3

author: Eric Schneller <[email protected]>
description: Dartson is a Dart library that can be used to serialize Dart objects into a JSON string and vice versa. It uses the new builder infrastructure.
Expand Down

0 comments on commit babf096

Please sign in to comment.