*
The moose likes Web Services and the fly likes Dynamic JSON passing to REST Web service and using it to insert data into mysql db Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Dynamic JSON passing to REST Web service and using it to insert data into mysql db" Watch "Dynamic JSON passing to REST Web service and using it to insert data into mysql db" New topic
Author

Dynamic JSON passing to REST Web service and using it to insert data into mysql db

Jack Rooney
Greenhorn

Joined: Dec 04, 2012
Posts: 14
Hello,

I am trying to pass a dynamic JSON string to my REST Web service which will in turn be used to populate a mysql db.
I can do this using a hard-coded JSON string,however I dont know how to pass a dynamic JSON string. Any insight is appreciated
as I am very new to this topic. Thanks a lot for all your time. I am attaching my code which I have for the hard-coded JSON
string parsing and adding to a mysql db.

My POJO:


My HibernateUtil class :


My SessionFactoryContextListener class :

My StackService.java

My Hibernate.cfg


Thanks,
Jack
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

There are plenty of JSON libraries: Gson, Jackson, Stringtree, ...

Choose one that pleases your sensibilities.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jack Rooney
Greenhorn

Joined: Dec 04, 2012
Posts: 14
Hi Bear,

Thanks a lot for the reply. I have already used GSON to parse the JSON string to a Java object. However, I am using a hard-coded JSON. I want to dynamicaly pass the JSON string in a URI and use that string to populate a mysql db.
Right now my URI is something like this :
http://localhost:8080/stack

I actually want the URI to be something like this :

curl -X POST -H'Content-Type:application/json' -d'{"stock_name":"GOOG"}' http://localhost:8080/stack

Kindly help me out.

Thanks,
Jack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic JSON passing to REST Web service and using it to insert data into mysql db