Skip to content

Commit

Permalink
register allow super types to be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Jun 28, 2024
1 parent ec29569 commit 8537712
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/CHANGELOG.ejson.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- `fromEJson<T>` now accepts a `defaultValue` argument that is returned if
`null` is passed as `ejson`.
- `register<T>` takes an optional `superTypes` argument to specify the super
types of `T` if needed.

## 0.3.1

Expand Down
4 changes: 2 additions & 2 deletions packages/ejson/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import 'encoding.dart';

/// Register custom EJSON [encoder] and [decoder] for a type [T].
/// The last registered codec pair for a given type [T] will be used.
void register<T>(EJsonEncoder<T> encoder, EJsonDecoder<T> decoder) {
TypePlus.add<T>();
void register<T>(EJsonEncoder<T> encoder, EJsonDecoder<T> decoder, {Iterable<Type>? superTypes}) {
TypePlus.add<T>(superTypes: superTypes);
customEncoders[T] = encoder;
customDecoders[T] = decoder;
}

0 comments on commit 8537712

Please sign in to comment.