I am looking for a way to transform a value during parse.
I have base64 encoded content inside a json formatted string with dynamic keys.
{
"key0": "irrelevant",
"key1": "VXNlbGVzcyBiYXNlNjQgY29udGVudA==",
"key2": "QW5vdGhlciBVc2VsZXNzIGJhc2U2NCBjb250ZW50",
"key3": {
"key4": "b25lIG1vcmUgVXNlbGVzcyBiYXNlNjQgY29udGVudA==",
"key5": "irrelevant",
"key6": {
"key7": "b25lIG1vcmUgdXNlbGVzcyBiYXNlNjQgc3RyaW5n",
"key8": "dXNlbGVzcyBiYXNlNjQgc3RyaW5n",
"key9": "TGFzdCB1c2VsZXNzIGJhc2U2NCBzdHJpbmcsIGJ1dCB0aGVyZSBjb3VsZCBiZSBtb3Jl"
}
}
}
I would like to replace the base64 content with a string and end up with something like this:
{
"key0": "irrelevant",
"key1": "replaced base64",
"key2": "replaced base64",
"key3": {
"key4": "replaced base64",
"key5": "irrelevant",
"key6": {
"key7": "replaced base64",
"key8": "replaced base64",
"key9": "replaced base64"
}
}
}
Javascript's JSON.parse method has the concept of a reviver function. Which I am aware that a "reviver" is a Javascript concept, however I am looking for something similar in Java. Here is an example of how it works on Javascript.
I am currently using Gson to parse the string to JsonElement.
NB: I do not have any information about the class type for this json string.
I know I could potentially parse the string to JsonObject and then possibly check for these strings recursively after.
However if someone knows of a way that I can do this during parse, please assist.