Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting / mapping Java code to Dart

Tags:

java

dart

My server is written in Java (on GAE). It includes some data classes that I share with an Android client, and would now like to also share with a Dart web client.

By 'share' I mean that I serialize them to JSON and use HTTP or GCM to sync them between client and server.

So, I'm looking for a tool that will generate Dart equivalents for the relevant Java classes, so I don't have to create them manually.

like image 891
Tom Avatar asked Jul 20 '14 22:07

Tom


2 Answers

Google Cloud Endpoints does this (converts data classes from GAE languages to client languages) but Dart is not currently amongst the support languages.

I guess GCE could be used to generate js, which could then be used in Dart app, but that is not ideal. So I think this is a possible solution but not an adequate one.

The other problem with this is that the code conversion of is tightly bound to the GCE service - it can't be used independently of GCE and the only way to get GCE to convert your classes is to include them in a GCE interface.

(If they added Dart support to GCE, made the code translator more independent of GCE, and added some features such as an @Ignore attribute, I think it would be very useful!)

like image 167
Tom Avatar answered Oct 22 '22 10:10

Tom


You can use this package to generate Dart client code for Google Cloud Endpoints http://pub.dartlang.org/packages/discovery_api_client_generator.

I also successfully used Protocol Buffers for a similar scenario
- http://pub.dartlang.org/search?q=protobuf
- http://pub.dartlang.org/packages/protobuf_builder
See also https://developers.google.com/protocol-buffers/

like image 44
Günter Zöchbauer Avatar answered Oct 22 '22 10:10

Günter Zöchbauer