• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Jackson or GSon to parse JSON  RSS feed

 
Mike London
Ranch Hand
Posts: 1495
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using Jackson or Gson to move data back and forth between a POJO and a JSON string, doesn't that mean you need to:

1. (Manually) Create a POJO manually for each JSON document structure?

2. Are then limited to one program per JSON document structure?

---

I am not sure if Jackson, for example, creates the POJO for you via reflection when reading the JSON or whether you have to create the POJO, manually, yourself.

Thanks,

- mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66260
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand (2) -- a single program can define multitudes of POJOs, why would you think you can have only one?
 
Mike London
Ranch Hand
Posts: 1495
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I don't understand (2) -- a single program can define multitudes of POJOs, why would you think you can have only one?


Right, I see how that was confusing. You're right, of course. Sorry for that confusion.

My main question was whether Jackson abstracts creating the POJO for you from the JSON document.

Do you know that answer?

Thanks Bear.

- mike
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66260
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never used Jackson, so I do not.
 
Mike London
Ranch Hand
Posts: 1495
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wondering the best approach now to writing a generic JSON "Get" algorithm.

So, if a user types in that they want the JSON data for some key like "ebooks" (from my posted data above), which is nested, I'm not sure how to extract that unless they pass in the path. It could be a nested object, or an array within an object, or whatever.

I could loop through the JSON, but when I get to "ebooks", how would I know if it's an array or a nested object, or whatever.

Interesting problem.

- mike
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike London wrote:My main question was whether Jackson abstracts creating the POJO for you from the JSON document.

With Jackson (and Gson and others), you simply annotate a POJO, and it inspects the annotations at runtime using reflection.

I'm working one right now:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!