I’m looking for some advice to come up with a design for a use case on which I’m working. As a REST request I receive a Json payload something like below
{
"marketEvent" :{
"category": "Finance"
"version": 1.0
}
"history" : {
"type" : "FX"
"value": 45.33
"role" : " Broker"
}
}
For different categories (in this example Finance), I need to access different values from the JSON. In case of Finance, I need to access history.type
, but in another category I might need to access another value.
I’m looking for a generic design in Java/Spring where I can configure different categories and what values I need to access and take action on that.
2
Answers
Jayway is perfect for this. Along with a map from the categories and paths to the data.
Dependency
Code
Output:
You many try library Josson. Function
caseValue()
can do the job.https://github.com/octomix/josson