1

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.
3
  • 1
    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. Commented 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 Commented Jun 24, 2013 at 9:57
  • 1
    I think it'll prove too much an headache than benefit to be honest! Commented Jun 24, 2013 at 13:17

1 Answer 1

2

Sorry, I can't comment as I have low rep. But would it be an option to parse the python into JSON objects, and Java use Jackson or GSON to parse them back into class objects?

Sign up to request clarification or add additional context in comments.

4 Comments

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?).
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.
Gave it a +1 because I like the idea. However, in my case I would prefer the way limelights described.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.