Jaguar-dart / jaguar_serializer

Format (JSON, XML, protobuf, mongodb, etc) and platform (server, client) agnostic serialization framework
172 stars 34 forks source link

user file with @required fields in the parameter are not getting generated properly #169

Open noisytempo opened 5 years ago

noisytempo commented 5 years ago
part 'device.jser.dart';

class Device {
  String uuid;

  //Name of the device
  String name;

  Device({@required this.uuid, this.name});

  Map<String, dynamic> toJson() => serializer.toMap(this);

  static final serializer = DeviceSerializer();

  static Device fromMap(Map map) => serializer.fromMap(map);

  String toString() => toJson().toString();
}

@GenSerializer()
class DeviceSerializer extends Serializer<Device> with _$DeviceSerializer {}

generated file is:

part of 'device.dart';

// **************************************************************************
// JaguarSerializerGenerator
// **************************************************************************

abstract class _$DeviceSerializer implements Serializer<Device> {
  @override
  Map<String, dynamic> toMap(Device model) {
    if (model == null) return null;
    Map<String, dynamic> ret = <String, dynamic>{};
    setMapValue(ret, 'uuid', model.uuid);
    setMapValue(ret, 'name', model.name);
    return ret;
  }

  @override
  Device fromMap(Map map) {
    if (map == null) return null;
    final obj = new Device();  //it should be final obj = new Device(uuid:''); 
    obj.uuid = map['uuid'] as String;
    obj.name = map['name'] as String;
    return obj;
  }
}
jaumard commented 5 years ago

Wrong repo, should be under jaguar_serializer I guess :)

tejainece commented 5 years ago

@noisytempo I will fix this.