hammock icon indicating copy to clipboard operation
hammock copied to clipboard

List of objects can also occur in JSON-Object notation form not just JSON-List form.

Open Toasterson opened this issue 10 years ago • 3 comments

Hi I'm getting the following error when loading some of my json Data.

Class '_CompactLinkedHashMap' has no instance method 'map'.

NoSuchMethodError: method not found: 'map' Receiver: Instance of '_CompactLinkedHashMap' Arguments: [Closure: (dynamic) => dynamic]

[[Sniped Stacktrace pointing towards error in hammock_core]]

This only occurs with some Lists of entities but not all.

The Stacktrace points to

QueryResult<Resource> jsonToManyResources(type, json) => new QueryResult(json.map((j) => jsonToResource(type, j)).toList());

all I could figure out is that json.map seems to not exists. It looks like you are expecting a different object from the JSON decoder than the one you get. This occurs in Dartium with manually configured serializers/deserializers hammock_mapper worked, but i can't use it due to its usage of reflection, which is incompatible with dart2js

Toasterson avatar May 05 '15 14:05 Toasterson

Turns out the Backend was responding with funny JSON answers for the affected Objects.

Instead of responding with [{"id":1,...},{"id:2,....}] it responded with {0:{"id":1,...},{"id:2,....}} I dont know if the second is valid JSON or not. thus i leave this Issue open until I have an answer. If its valid, then we only need a little check which function to execute either jsontomanyresources or jsontoresource.

Toasterson avatar May 06 '15 07:05 Toasterson

It turns out that a List of Objects can not only occur in JSON-List notation but also in JSON-Object notation. JSON-Object notation gets serialized into a map object, which has no map function. I suggest using the forEach function.

Toasterson avatar May 06 '15 09:05 Toasterson

Fixed with PR #19

Toasterson avatar May 06 '15 12:05 Toasterson