Help coderanch get a
new server
by contributing to the fundraiser
  • 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

How to Test Dynamic JSON Responses

 
Ranch Hand
Posts: 91
IntelliJ IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've got a set of API's which returns a set of data (JSON format). 95% of the data is static and the rest of the data would change every minute or so, and I need to test these API's. The requirements are
1. Check if the key-value pair are matching (assert) for the static part of the data.
2. Check if the key(s) are present in the dynamic part of the data.

I did look around in Jackson and simpleJsonParser but could not find anything. Is there any library which helps me to do this? Or would I have to write the logic for this from scratch?

Thanks
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you planning to check directly as JSON string or after your convert to an object/class?

The static part is simply one-to-one mapping but the dynamic part can be a Map<String,Object> or Map<String,String> in that class.
 
Sheriff
Posts: 22791
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For which Jackson has annotations JsonAnyGetter and JsonAnySetter. For example:
Note that the value type can be more specific if needed, for instance Integer, String or even a custom class. Just make sure to match this in the field and two methods
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic