-1

I would like to knows if someone can show me the right way to generate Java classes from a json File ?

for example if we have the following json file :

{
  "Personne": {
    "Name": "Job Moun ",
    "Phone": "062352665566"
  }
}

I want to generate Java code automatically, something like that :

public class Personne{

private String Name;
private String phone;

....
}
Ayoub Mounji
  • 7
  • 1
  • 6
  • 1
    see : http://examples.javacodegeeks.com/core-java/xml/bind/jaxb-json-example/ – yahya el fakir May 06 '15 at 08:40
  • There are many (online) tools available. Example: http://www.jsonschema2pojo.org/ – User404 May 06 '15 at 08:42
  • Lots of frameworks exist that will solve this problem for you. Jackson ( https://github.com/FasterXML/jackson ) and GSON (https://code.google.com/p/google-gson/) are both worth looking at and both make this pretty easy. – DaveH May 06 '15 at 08:44
  • @yahyaelfakir generate a class file not the object, read the question – Olayinka May 06 '15 at 08:53
  • It's not as simple as your example, but Swagger has quite a few export options once you define the objects: http://editor.swagger.io – HairyFotr May 06 '15 at 11:50
  • If you have node.js and npm installed, you can take a look at this package: https://github.com/rtoshiro/json2poxo – Hamiseixas Aug 31 '15 at 16:39

1 Answers1

-1

You can have a look at this online tool if it's sufficient for you:

https://javafromjson.dashingrocket.com

or use some templating engine like Velocity in conjunction with Jackson library for reading JSON. Here you have some basic functionality:

http://wiki.fasterxml.com/JacksonInFiveMinutes

m4tt
  • 102
  • 4