添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm looking for a good way to "copy" / convert a model from Python source code to Java source code. My idea is to use the Python django framework on a server to generate entity model classes. On the other side I would like to convert the entity classes to Java to use them in a native Android project.

Do you have any recommendations what I can use to convert the python entity classes to Java? It should be possible to trigger the convertion every time I change the model in python.

Best regards, Michael

PS: If you're interessted, this is what the project structure will look like:

python django project

  • connects to the database
  • will be used to generate entity model classes
  • using REST API for data exchange between Android devices and the server
  • java model library

  • this will be my Java library which should contain the converted model of the python django project
  • android project

  • this will be my android app which will use the model of the java model library
  • it should interact with the server via REST API. That's why the model in the java and python project have to be equals.
  • There isn't a "good way" since converting from a dynamic language like Python to a statically typed language like java requires you to infer the missing types. What I would do is go the extra mile and write the Java code myself. Thinking about it, it shouldn't be that much of a hassle and you'll effectively reduce the clutter a conversion is likely to introduce. Henrik Andersson Jun 24, 2013 at 9:28 Thanks for the reply. That's actually one option I've thought about. I hoped that there's a way, e.g. if my python variable names contain the datatype e.g. string_variable_name Michael Jun 24, 2013 at 9:57 Thanks for your reply. Guess it will not work for me, because the Android application requires to use the model at any time, even if the app has no connection to the server. But it will only be able to modify the model if it's connected to the server. If I do get your idea in the wrong way, please help me understanding it. What I need is to convert the python classes to java classes within my IDE. I do not need a model convertion during runtime (guess that was your idea, right?). Michael Jun 24, 2013 at 14:30 Quick link in case you haven't seen it: stackoverflow.com/questions/153491/… JSON is a quite famous programming way to structure objects, Jackson and GSON can be downloaded and run on the Java source code, so no internet connection required. They allow for JSON objects to be analysed, and I was simply suggesting analysing the objects and creating Java classes accordingly. You can pick out bits of information easily with JackSON and GSON, it was a simple suggestion, but would require a lot of parsing computation. Jim Jun 24, 2013 at 15:11 Gave it a +1 because I like the idea. However, in my case I would prefer the way limelights described. Michael Jun 25, 2013 at 10:41 It's fine, I was just trying to help. If it's not a usual thing then code it yourself, my option was more an option if you needed automatic fast constant code trading. For like industry size. It would be a lot of work, and I mean a lot, but it can be done. They are both Turing complete at the end of the day. Jim Jun 25, 2013 at 15:48

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question . Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers .