Closed rubenferreira97 closed 4 months ago
I don't get why you are asking? You have the correct way right there.
Everything uses MapperContainer internally, even if you are not explicitly calling it.
If you want a 'less advanced' way do (jsonDecode(jsonList) as List).map((item => PersonMapper.fromMap(item)).toList()
Thanks for the response @schultek. I was hoping the Mapper
would generate a method to decode json arrays like:
List<T> Mapper.fromJsonArray(String json) { ... }
So we could use like:
final List<Person> persons = PersonMapper.fromJsonArray(json);
Json array literals are valid and some APIs return them. Would it be reasonable to add it to the generateStaticDecoders
?
I have no plans to add a specific method for that.
I had the same question today also. For people new to dart_mappable, the suggested approach seems like exposing an internal detail of the package. I had hoped for something like:
static const fromMap = PersonMapper.fromMap;
static const fromJson = PersonMapper.fromJson;
static const fromJsonList = PersonMapper.fromJsonList; // returns List<Person>
In my project, I am using
dart_mappable
to facilitate JSON serialization and deserialization for my model classes. While the package works seamlessly for single object mapping with the MapperContainer, I expected a simplified way to handle lists of JSON objects without relying onMapperContainer
.Is there any built in way to accomplish this?