1

I have a complex JSON from server which needs to be turned into java objects.

{"menus":[{"title":"Jewellery","menu_columns":[{"title":"category","menu_items":[{"title":"Earrings"},{"title":"Necklaces"},{"title":"Necklace Sets"},{"title":"Anklets"},{"title":"Mangalsutra"},{"title":"Pendants"},{"title":"Bangles \u0026 Bracelets"},{"title":"Rings"},{"title":"Maang Tikka"},{"title":"Keychains"},{"title":"Baju Band"},{"title":"Brooch"},{"title":"Hair Pins"},{"title":"Jewellery Box"},{"title":"Nose Ring"},{"title":"Waist Belts"},{"title":"Jewellery Combo"},{"title":"Watches"},{"title":"Other"}]},{"title":"Type","menu_items":[{"title":"Bridal Jewellery"},{"title":"Temple Jewellery"},{"title":"Statement Jewellery"},{"title":"Thewa Jewellery"},{"title":"Handmade Jewellery"},{"title":"Filigree Jewellery"},{"title":"Pearl Jewellery"},{"title":"High End Jewellery"},{"title":"Ethnic Jewellery"},{"title":"Kundan Jewellery"},{"title":"Jhumkas"}]},{"title":"Earrings","menu_items":[]}]},{"title":"Sarees","menu_columns":[{"title":"by fabric","menu_items":[{"title":"Cotton Sarees"},{"title":"Art Silk Sarees"},{"title":"Georgette Sarees"},{"title":"Chiffon Sarees"},{"title":"Net Sarees"},{"title":"Crepe Sarees"},{"title":"Silk Sarees"},{"title":"Viscose Sarees"},{"title":"Tissue Sarees"},{"title":"Satin Sarees"},{"title":"Velvet Sarees"},{"title":"Jute Sarees"},{"title":"Brasso Sarees"},{"title":"Shimmer Sarees"},{"title":"Brocade Sarees"},{"title":"Jacquard Sarees"},{"title":"Dupion Sarees"},{"title":"Saree Blouses"},{"title":"Sarees Combo"}]},{"title":"by type","menu_items":[{"title":"Supernet Sarees"},{"title":"Banarasi Sarees"},{"title":"Banarasi Silk Sarees"},{"title":"Kalamkari Sarees"},{"title":"Chanderi Sarees"},{"title":"Tussar Silk Sarees"},{"title":"Organza Sarees"},{"title":"Wedding Sarees"},{"title":"Printed Sarees"},{"title":"Lehenga Sarees"},{"title":"Bhagalpuri Silk Sarees"},{"title":"Heavy Work Sarees"},{"title":"Party Wear Sarees"},{"title":"Traditional Sarees"},{"title":"One Minute Sarees"},{"title":"Kerala Sarees"},{"title":"Bandhani Sarees"},{"title":"Ikat Sarees"},{"title":"Hand Woven Sarees"}]},{"title":"bollywood sarees","menu_items":[{"title":"Kareena Kapoor Sarees"},{"title":"Katrina Kaif Saree"},{"title":"Madhuri Dixit Sarees"},{"title":"Deepika Padukone Saree"},{"title":"Priyanka Chopra Saree"},{"title":"Sridevi Sarees"},{"title":"Anushka Sharma Saree"},{"title":"Shilpa Shetty Sarees"},{"title":"Sonakshi Sinha Saree"},{"title":"Bipasha Basu Sarees"},{"title":"Aishwarya Rai Saree"},{"title":"Sonam Kapoor Saree"},{"title":"Vidya Balan Saree"}]}]},{"title":"Salwar Kameez","menu_columns":[{"title":"","menu_items":[{"title":"Dress Materials"},{"title":"Anarkali Salwar Kameez"},{"title":"Cotton Salwar Kameez"},{"title":"Party Wear Salwar Kameez"},{"title":"Pakistani"},{"title":"Wedding"},{"title":"Salwars \u0026 Churidars"},{"title":"Semi Stitched Salwar Suits"},{"title":"Bollywood Salwars"},{"title":"Salwar Combo"}]}]},{"title":"More","menu_columns":[{"title":"bridal","menu_items":[{"title":"Bridal Sets"},{"title":"Bridal Lehengas"},{"title":"Bridal Sarees"}]},{"title":"lehengas","menu_items":[{"title":"Ghagra Choli"},{"title":"Lehenga Choli"},{"title":"Bollywood Lehengas"}]},{"title":"bags","menu_items":[{"title":"Hand Bags"},{"title":"Clutches"},{"title":"Wallets"},{"title":"Tote Bags"},{"title":"Backpacks"},{"title":"Sling Bags"},{"title":"Potli Bags"}]},{"title":"other apparel","menu_items":[{"title":"Kurtas \u0026 Kurtis"},{"title":"Tops"},{"title":"Stoles \u0026 Dupattas"},{"title":"Tunics"},{"title":"Leggings"},{"title":"Shawls"},{"title":"Dresses"},{"title":"Skirts"}]}]},{"title":"Home Decor","menu_columns":[{"title":"accessories","menu_items":[{"title":"Wall Decals"},{"title":"Wall Clocks"},{"title":"Ipad Covers"},{"title":"Laptop Skins"},{"title":"Phone Cases"},{"title":"Candles"},{"title":"Flowers"},{"title":"Artificial Flowers"},{"title":"Table Lamps"},{"title":"Trays"},{"title":"Vases"},{"title":"Wall Art"},{"title":"Tea Kettle"},{"title":"Paintings"},{"title":"Stationery"},{"title":"Photo Frames"},{"title":"Decorative Plates"},{"title":"Pots"},{"title":"Sculptures"},{"title":"Other"}]},{"title":"furnishing","menu_items":[{"title":"Pillow Covers"},{"title":"Bed Sheets"},{"title":"Duvet Covers"},{"title":"Quilts"},{"title":"Table Cloth"},{"title":"Table Mats \u0026 Runner"},{"title":"Carpets"},{"title":"Jaipuri Razai"},{"title":"Other"}]}]},{"title":"Gifts","menu_columns":[{"title":"by recipients","menu_items":[{"title":"For Him"},{"title":"For Her"},{"title":"For Kids"},{"title":"For Dad"},{"title":"For Mom"},{"title":"For Husband"},{"title":"For Wife"},{"title":"For Boyfriend"},{"title":"For Girlfriend"},{"title":"For Brother"},{"title":"For Sister"}]},{"title":"by occasions","menu_items":[{"title":"Birthday"},{"title":"Engagement"},{"title":"Wedding"},{"title":"Anniversary"},{"title":"Congratulation"},{"title":"House Warming"},{"title":"Office Opening"}]},{"title":"by festivals","menu_items":[{"title":"Christmas Gifts"},{"title":"Christmas Decorations"},{"title":"Valentine Gifts"},{"title":"Ganesh Chaturthi"},{"title":"Rakhi Online"},{"title":"New Year"},{"title":"Teachers Day"},{"title":"Engineers Day"},{"title":"Thanksgiving"},{"title":"Onam gifts"},{"title":"Navratri lehenga Chaniya Choli"},{"title":"Diwali Gifts"}]}]},{"title":"Lehenga","menu_columns":[]}]}

I would like to save time writing the Java objects (models) corresponding to such a complex JSON manually.

Are there any tools which can help convert this complex JSON into java models quickly?

I had a look at http://www.jsonschema2pojo.org/ but I think it was not generating the correct Java POJOs. I'm not looking for libraries for converting JSON into java objects(like GSON, Jackson) but for online tools for generating the java model classes.

Mifeet
  • 12,949
  • 5
  • 60
  • 108
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
  • Judging by the answers it attracts - this question could use some reformulating to be more precise. Mention of jsonschema2pojo suggests you want to generate POJOs, java classes from json, not java objects (which, when you already have a pojo, is simple and already covered: http://stackoverflow.com/questions/1688099/converting-json-to-java ) – Deltharis Jul 06 '15 at 11:50
  • [this](http://pojo.sodhanalibrary.com/) seems to work well. I tried it with your sample json, and it generated all relevant classes and subclasses. – Eric Leibenguth Jul 06 '15 at 11:55

3 Answers3

0

I wrote a simple JavaScript tool to automatically generate the java class files. It only works on Chrome browser. Here is the link:

http://www.karvitech.com/Json2Java.html

Ray
  • 16,025
  • 5
  • 31
  • 51
-2

can you have a look at Gson API. I am currently using it in my project and it is working fine for me...

Pavan Kumar K
  • 1,360
  • 9
  • 11
-2

Think about Jackson library. Simply use ObjectMapper readValue() and writeValue()

The best explanation I found in the past is here: http://www.mkyong.com/java/how-to-convert-java-object-to-from-json-jackson