Closed cgarciae closed 9 years ago
No worries! Redstone relies on the dart:convert library to encode and decode JSON objects. More specifically, it uses the JSON codec.
Moreover, since the JSON codec only supports Map
and List
objects, the redstone_mapper plugin can be used to convert other data types to maps and lists, which can be serialized to JSON.
Thanks! Worked great and its much easier to use than Exportable.
BTW: have you thought of or do you currently have a Redstone helper for the client? It would be very nice to have Redstone-style "Requester" (as opposite of server) to create GET and POST requests to certain routes, convert JSON responses to objects, deal with error sent from the server, etc.
Angular es great, but its still to manual is the sense that you have to decode and handle the response yourself. I imagine something like this for the client.
//Response handler from the route "route/user/someName", JSON by default
@app.Response("route/user/:name")
User GetUser (@Decode User user)
{
//Some prepossessing
return user;
}
//Somewhere else
Future<User> userFuture = app.request ("route/user/$userName");
//Or directly inline
app.request ("route/user/$userName").then ((User user) => ...);
//CatchErrors
app.request ("route/user/$userName")
.then ((User user) => ...)
.catchError (serviceUnavailableHandler, test: (e) => e is ServiceUnavailable);
Id try to do the plugin but I have no experience with annotations or http in general :(
Closing this issue for now. Maybe we can create an issue for a rpc plugin, but I don't plan to implement this in the near future.
Sorry this is not an actual issue, but I see you serialize automatically serialize some responses to JSON. I've been searching a lot on how to serialize and haven't got any satisfactory answer.
Can you please tell me what method you use to serialize objects?