Low level JSON manipulation library for Java

146 Views Asked by At

I am looking for a 3rd party library which can manipulate entities stored as JSONs. This is intended to be used in the (cucumber) test framework to specifically tailor predefined JSON requests to a specific situation. For example let`s consider the following JSON

{
    "user": {
        "name": "Bob",
        "age": 27,
        "email": "[email protected]"
    }
}

Naturally the JSON above has it`s appropriate POJO which is used by the application/test framework.

In the feature file this should look something like:

Given predefined user Bob with changes:
 |node    |newValue|
 |user.age|-5      |
When I register Bob
Then expect error INVALID_AGE.

In this case before the entity is deserialized its age attribute would be replaced by -5 thus when we receive the POJO it already has -5 in it. Something like this should be achievable with the ObjectMapper, navigate the JSON node by node and update some values.

This is required to ensure that we do not have to change code in the step definitions in case the API changes (fields get added or removed). Naturally the feature files themselves need to be updated but this can be done by non developers.

Also with this approach its easy to create a generic JSON template and only update specific fields instead of in each scenario to create a complex entity from scratch.

Does such a library or something similar exist?

0

There are 0 best solutions below