Skip to content

Add ability to reference values inside nested objects #196

Closed
@jmrboosties

Description

@jmrboosties

I ran into this problem when trying to parse some JSON with unnecessary nesting (for my purposes) in it's structure:

"name": "document collection",
"id": 123
"documents": {
	"href": "https://urltodocuments",
	"total": 3
}

I'd like to have an object that looks like this:

class DocCollection {

    String name;
    int id;
    int totalDocuments;
    String documentsUrl

}

Initially, I tried this:

@JsonKey(name: 'documents, fromJson: _getTotalDocuments)
int totalDocuments;

@JsonKey(name: 'documents', fromJson: _getDocumentsUrl)
String documentsUrl;

//Outside of class
int _getTrackCount(Map<String, dynamic> input) {
	return input['total'];
}

String _getTracksUrl(Map<String, dynamic> input) {
	return input['href'];
}

However the package doesn't allow you to tag two variables with the same key name. This would have been a work around anyway, what I'd really like to do is something like this:

@JsonKey(name: 'documents.total)
int totalDocuments;

@JsonKey(name: 'documents.href')
String documentsUrl;

Which would achieve the same effect. Let me know if this is something that can be added. I know I've been making a lot of requests, I really appreciate you guys listening and responding!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions