New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
force key type #51
Comments
@Miamoto-Musashi Hi 👋 Here are all supported date formats.
To tell that you want a date object just copy and paste one of the formats and the generator will detect it. {
"updated": "2008-09-15T15:53:00",
"created": "2008-09-15T15:53:00"
} Or your mean to speed up the coding by adding the date keyword? |
@iamarnas thx for clarifying, is it documented the date feature? |
@Miamoto-Musashi Can you provide me an exact example with raw JSON and final Dart code?
No 😄 But I can add this, np. |
Hi @iamarnas // REQUEST
{
"__className": "Request.model",
"key": "5621f8a9-f05a-4469-bddf-0cdb56b24771-3",
"candidates.candidate": [{}], <-- type Candidate
"cargoes.cargo": [{}], <-- type Cargo
"cargoSummary.summary": <-- type Summary
"loadContacts.contact": [{ <--type Contact
// "__className": "Contact.model",
"key": "110afe06-ec31-4d9b-b933-d9e060c7bcb7",
"address": null,
"phone": "+393477972533",
"organizationKey": "110afe06-ec31-4d9b-b933-d9e060c7bcb7",
"countryCode": "ITA",
"lastUpdate": "2015-10-05T21:46:54+07:00", //UTC time, need to be converted from and to FrontEnd
"r@isOrigin": true
}], //minutes
"unLoadContacts.contact": [{
"key": "110afe06-ec31-4d9b-b933-d9e060c7bcb7",
"address.address": null, <--type Address
"phone": "+393477972533",
"organizationKey": "110afe06-ec31-4d9b-b933-d9e060c7bcb7",
"countryCode": "ITA",
"lastUpdate": "2015-10-05T21:46:54+07:00", //UTC time, need to be converted from and to FrontEnd
"r@isOrigin": true
}],
},
// CANDIDATE
{
"__className": "Candidate.model",
"distance":{
"lastUpdate": "2015-10-05T21:46:54+07:00",
},
"motorKey":"110afe06-ec31-4d9b-b933-d9e060c7bcb7"
},
.....
would generate something similar to: // assuming everything on the same folder by #45
import 'candidate.model.dart';
import 'cargo.model.dart';
import 'summary.model.dart';
class Request {
String key;
List<Candidate> candidates;
List<Cargo> cargoes;
Summary cargoSummary;
List<Contact> loadContacts;
List<Contact> unLoadContacts;
....
} somewhere else we defined the Cargo, Candidate objects |
@Miamoto-Musashi Would look like this with enhancement. {
"__className": "Request.model",
"key": "5621f8a9-f05a-4469-bddf-0cdb56b24771-3",
"candidates.candidate": [{}], <-- type Candidate
"cargoes.cargo": [{}], <-- type Cargo // If you want to have cargo in the same directory, then you need to provide an object. Otherwise will be created an empty class.
"cargoSummary.summary": <-- type Summary
"loadContacts.contact": [{ <--type Contact
// "__className": "Contact.model", <- This only works for main json objects as base class name.
// Class name takes from the list object's json key. In this case would be `Concat`with echancement.
"key": "110afe06-ec31-4d9b-b933-d9e060c7bcb7",
"address": null,
"phone": "+393477972533",
"organizationKey": "110afe06-ec31-4d9b-b933-d9e060c7bcb7",
"countryCode": "ITA",
"lastUpdate": "2015-10-05T21:46:54+07:00",
"r@isOrigin": true
}],
"unLoadContacts.contact": [{}], // <- For duplicates don't need provide object would create from the first object.
}, It can be fixed but you would need to manually handle your empty objects. It is not possible to provide results without any parameters. |
the objects wouldn't be empty by my example in jsonc file you can find in the root the definition of the Candidate object when generated everything would be consistent; yes is an enhancement |
@Miamoto-Musashi A question. What wrong if you put |
@iamarnas I need it to be separated cause is referenced in other json but with smaller attribute set, what I do today is to generate it from the root with __className, move all dart models |
@Miamoto-Musashi HI 👋 Example:{
"__className": "Candidate.model",
"__path": "/lib/models/candidate", // <- override default path with a new one by adding '__path' key
"distance":{
"lastUpdate": "2015-10-05T21:46:54+07:00",
},
"motorKey":"110afe06-ec31-4d9b-b933-d9e060c7bcb7"
} any suggestions on how to improve it are welcome 😃 |
on a first run seems working fine, thank you. |
Hi @iamarnas I found a bug: I have this jsonc {
...
"trailers": [
{
"key": "Trailer",
"dimension": null,
"type.trailertype": {}
}
],
},
//EQUIPMENT
{
"__className": "Equipment.model",
//....
"type.trailertype": {}
},
//TRAILERTYPE
{
"__className": "TrailerType.model",
"key": "key",
"r@type": "string",
"code":"string"
},
the trailer type model on the root is generated correctly with the underscore and camel case perfectly balanced (only style warning sort constructors before other members) class TrailerType {
String key;
String type;
String code;
TrailerType({this.key, @required this.type, this.code});
factory TrailerType.fromJson(Map<String, dynamic> json) => TrailerType(
key: json['key'] as String,
type: json['type'] as String,
code: json['code'] as String,
);
Map<String, dynamic> toJson() => {
'key': key,
'type': type,
'code': code,
};
} but the trailer type in equipment is generated with wrong name in file and in class: file name should be import 'trailertype.model.dart'; <-- should be `import trailer_type.model.dart`
class Equipment {
String key;
String name;
String organizationKey;
Trailertype type; <-- should be TrailerType
Equipment({this.key, this.name, this.organizationKey, this.type});
factory Equipment.fromJson(Map<String, dynamic> json) => Equipment(
key: json['key'] as String,
name: json['name'] as String,
organizationKey: json['organizationKey'] as String,
type: json['type'] == null
? null
: Trailertype.fromJson(json['type'] as Map<String, dynamic>),
);
Map<String, dynamic> toJson() => {
'key': key,
'name': name,
'organizationKey': organizationKey,
'type': type?.toJson(),
};
}
|
@Miamoto-Musashi Thanks for this reporting. I will fix it fast as possible. |
@Miamoto-Musashi I found the problem. The problem is in your code, to tell the generator where you want uppercase you need separate words by uppercase or dash. Otherwise, the generator takes it as a word. Example: {
"key": "Trailer",
"dimension": null,
"type.trailertype": {} // <- should be "type.trailerType" or "type.trailer_type"
} I would you recommend to follow some principles. Example: for all
Do you know that you can enable in the settings sort constructors first? |
I'm closing it because no see issues with it at the moment. Open the new issues report if you have some problem that relates to this. |
would be nice to be able to force property type
suppose we have:
this will create 2 useless objects
Updated
andCreated
, would be nice instead to tell json2dart to create the corresponding properties in the class as Date objectsprobably to follow the naming pattern can be:
The text was updated successfully, but these errors were encountered: