• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing JSON using Spring MVC and hibernate

 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following setup working fine and it's printing the following JSON as expected:

   

Following code works fine and prints above JSON:

 


But I have few more things involved like Hibernate 4.3.5 from where I am getting some details so I have modified the above code as follows:


I am getting following JSON response for the above :

 



In case if someone is wondering what's the output of `empList`. from the below line of code of the controller, I tried printing it like this :


 


and it's getting printed like this :




Could anyone tell me what am I doing wriong above? I mean how can I print all the ID and Name in the JSON using `empList` from the above code?




 
Greenhorn
Posts: 7
Hibernate Spring Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jack Tauson wrote:I have the following setup working fine and it's printing the following JSON as expected:

   

Following code works fine and prints above JSON:

 


But I have few more things involved like Hibernate 4.3.5 from where I am getting some details so I have modified the above code as follows:


I am getting following JSON response for the above :

 



In case if someone is wondering what's the output of `empList`. from the below line of code of the controller, I tried printing it like this :


 


and it's getting printed like this :




Could anyone tell me what am I doing wriong above? I mean how can I print all the ID and Name in the JSON using `empList` from the above code?






Hi jack, are you want to create a RESTfull APIs using spring?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the first example your EmplyeeStatus takes the name and id parameters and populates the object correctly.

In the second case you have added a constructor to take a List<Employee> which makes no sense, but in any case does not populate the name or id fields.

You probably wanted to create an EmployeeStatus from an Employee.
And therefore I would suggest changing the addEmployeeStatus method of MyJSON to loop over the supplied List<Employee> and create a new EmployeeStatus for each Employee.

Hope that makes sense?
 
Jack Tauson
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:In the first example your EmplyeeStatus takes the name and id parameters and populates the object correctly.

In the second case you have added a constructor to take a List<Employee> which makes no sense, but in any case does not populate the name or id fields.

You probably wanted to create an EmployeeStatus from an Employee.
And therefore I would suggest changing the addEmployeeStatus method of MyJSON to loop over the supplied List<Employee> and create a new EmployeeStatus for each Employee.

Hope that makes sense?



Thank you, Dave.  I did exactly as you suggested and it worked perfectly fine. I also deleted the constructor which I defined to take a `List<Employee>`.
 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic