Closed atebitftw closed 10 years ago
You have to use the decode function with the JSON codec (from the dart:convert
library):
return HttpRequest
.postFormData('/foo', {})
.then((response) => decode(JSON,decode(response.response), Bar))
.then((result) => print(result));
You can see a working example here.
This API is indeed a bit confusing. I'm thinking about including the encodeJson()
and decodeJson()
functions in the future releases
I tried with JSON.decode() as you illustrated, but it appears to make no difference. I still get a [Map, Map] instead of [Object, Object]. It seems to encode just fine on the server side (in fact all the data is correctly present in each Map), so not sure what's going on. :)
Yeah, this is another thing that can be improved. If the class you are trying to decode to wasn't mapped by the transformer, the decode function will return the input. You just have to include your encodable classes in your entry-point (see here for an example).
Seems reasonable, once I understand the need to do that. Thanks! On Sep 14, 2014 3:46 PM, "Luiz Henrique Farcic Mineo" < notifications@github.com> wrote:
Yeah, this is another thing that can be improved. If the class you are trying to decode to wasn't mapped by the transformer, the decode function will return the input. You just have to include your encodable classes in your entry-point (see here https://github.com/luizmineo/io_2014_contacts_demo/blob/master/web/index.dart for an example).
— Reply to this email directly or view it on GitHub https://github.com/luizmineo/redstone_mapper/issues/4#issuecomment-55538937 .
It's working now. Although I noticed the client-side transformer (I think) doesn't like the, "view" parameter on fields: "@Field(view:'something')". Once I removed those, then it works as expected, otherwise I get compilation errors.
Thanks! This is probably a bug in the transformer. I'll take a look at this.
Fixed in v0.1.8
I'll try a simple example to explain the problem.
given:
on server side:
on client side:
I would expect output to be:
But instead I just get the JSON object.
Am I overlooking something obvious? Thanks in advance :)