This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How to make this json parsing code dynamic which takes POJO.class as input?

 
Ranch Hand
Posts: 1256
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a json parsing code as below:





MyBean is the class with POJO which will hold the results. This works fine when I used different POJOS and use code as below:



or




and so on.


I want to make this code dynamic by creating a method for it. How can I pass MyBean dynamically?

thanks

 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "mapper"?
 
Monica Shiralkar
Ranch Hand
Posts: 1256
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the entire code:



thanks
 
Bear Bibeault
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you're using some org.boon 3rd party library? Might be something useful to point out.
 
Sheriff
Posts: 6261
167
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're asking if you can pass in a type to a method, the answer is yes, by using generics.  But things can get a little complex if you try to instantiate a generic type (see below).

I don't know if the below is the sort of thing you want to be able to do, but it may give you a clue about how create your method.  I'm just guessing with all the mapper stuff.
 
What's that smell? Hey, sniff this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!