This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are plenty of JSON libraries: Gson, Jackson, Stringtree, ...

Choose one that pleases your sensibilities.
 
Jack Rooney
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Whatever. Here's a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic