Converting / mapping Java code to Dart Converting / mapping Java code to Dart dart dart

Converting / mapping Java code to Dart


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!)


The "ad-hoc Java-to-Dart translator" was "written in three days" by Stefan Matthias Aust (last revised on 2014-01-03). The author notes that "there might be errors", and that "I didn't cover annotations and some esotheric[sic] generics syntax."

He provides some useful guidelines for keeping your Java code dart friendly:

"Because Dart doesn't support overloading methods, I strongly recommend to first rename (using your favorite IDE) those methods in Java. I also noticed that Dart doesn't like if types, fields, or methods have the same name. Again, I recommend to rename all such occurrences before translating. He also notes that Dart doesn't support a character type.


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/