• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Test Dynamic JSON Responses  RSS feed

 
Vineeth Menon
Ranch Hand
Posts: 79
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!