redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

About JSON serialization #51

Closed cgarciae closed 9 years ago

cgarciae commented 9 years ago

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?

luizmineo commented 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.

cgarciae commented 9 years ago

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.

luizmineo commented 9 years ago

Currently, we have no plans for a HTTP client. Although, you can use the clients provided by the Dart SDK, or frameworks such as Angular. See here for an example that uses the HttpRequest class from dart:html, and here for an example that uses the http client from Angular.

cgarciae commented 9 years ago

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 :(

luizmineo commented 9 years ago

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.