• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

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: 22850
132
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
reply
    Bookmark Topic Watch Topic
  • New Topic