0

In Python i have a class with some string attributes and a function that returns an object of this class with atttributes set (sometimes can return an array of objects). Theres any way to get this return in Java? Where i can see the strings of the object?

I Tried Jython but couldnt make it work!

Reis
  • 15
  • 2

1 Answers1

0

Use json.dump function in Python to serialize your object into json format. Then use something like json.org library in Java to parse this object into Java object, some example over here.

Mind that not every object might be serializable, in general data structures like dictionaries or lists are easily serializable, from your description it seems like you want to move an instance of an object from one program into another, which is not possible to be done automatically and requires human work in rewriting the code as instances of classes contain not only data but also functions (methods).

Good luck!

Marek
  • 1,413
  • 2
  • 20
  • 36
  • To explain better: In Java i have the GUI, and the title, description, image source for the GUI element all comes from this Python script. its just a bunch of strings. So basically i click a button in the GUI, execute the script that returns the Strings for the GUI. Thanks for your answer, you ill look into it – Reis Sep 29 '18 at 02:47
  • alright, my advice is to put those strings into `dictionary` or `list` (or mixture of both if you need more complicated hierarchy). This you can `serialize` into `json`. Then you have your entire object as a one string. You can move this string between programs using whatever mean of communication you prefer and `parse` back. – Marek Sep 29 '18 at 02:50
  • Ok, i manage to save a json file of the object and import into Java. Now only remains making the communication to generate the json! Thank you – Reis Sep 29 '18 at 03:32