Skip to content

Commit

Permalink
Arreglado problema con serialización (ver google/json_serializable.da…
Browse files Browse the repository at this point in the history
  • Loading branch information
Foo-Manroot committed Jun 4, 2020
1 parent 7610661 commit 0b3dfd7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/src/modelos/Definic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ abstract class Definic {
* Al ser una clase abstracta, hay que crear un constructor propio:
* https://github.com/dart-lang/json_serializable/issues/606#issuecomment-587993029
*/
factory Definic.fromJson(Map<String, dynamic> json) {
factory Definic.fromJson (Map<String, dynamic> json) {


switch (json ["clase"]) {

Expand All @@ -55,8 +56,9 @@ abstract class Definic {
return Expr.fromJson (json);

default:
throw ArgumentError ("Invalid value provided: ${json["clase"]}. "
" Should be one of ${ClaseAcepc.values}"
throw ArgumentError ("Invalid class value provided: ${json["clase"]}. "
"Should be one of ${ClaseAcepc.values}. "
"This JSON's keys are: ${json.keys}"
);
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/src/modelos/Expr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ class Expr extends Definic {
/**
* Constructor por defecto.
* Simplemente inicializa los atributos
*
* El parámetro "clase" se declara explícitamente para poder serializar correctamente
* (ver https://github.com/dart-lang/json_serializable/issues/274).
*/
Expr (String this.texto
, { String id = null, List<Acepc> definiciones = null }
, { String id = null, List<Acepc> definiciones = null , ClaseAcepc clase}
):
this.definiciones = (definiciones == null)? [] : definiciones
, super (id, ClaseAcepc.frase_hecha)
Expand Down
42 changes: 42 additions & 0 deletions lib/src/modelos/Expr.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b3dfd7

Please sign in to comment.