dart-league / dson

dart library which converts Dart Objects into their JSON representation
Apache License 2.0
66 stars 14 forks source link

Think about this: List of random typed objects #21

Closed LexiBigCheese closed 6 years ago

LexiBigCheese commented 7 years ago

Think about a list of random typed objects.

how would you deal with them?

Maybe try storing their type name with them.

I did it, but i don't know how your code works so i can't put it in yours, but a push in the right direction might be

{
  'data': new SerializableBaconSomething(shouldDo:true,),
  'type': SerializableBaconSomething,
}

Also, look at my package: server_client_comm

luisvt commented 7 years ago

I'll take a look into it.

LexiBigCheese commented 6 years ago

i did it. myself. in my fork. i call it: Smart. it does it whenever it encounters a dynamic or an object. it stores the runtimeType in objects, but if in a map if you put a runtimeType key then it will become that type. it's cool though.

class A {
  Map x; //still will be a map, put types in there if you want
}

class B {
  dynamic x; //if was originally a map with a "runtimeType" key then it will be that type on deserialize
}