I have a Java backend system that processes JSON information sent by a client. In order to determine what kind of processing should take place I use a field in the JSON called "type"
My backend system checks the "type" and executes specific Java code based on the type.
Instead of checking the type and executing the code that is hard coded into my Java class, I'm interested in exploring ways to run code from an external database. This way when I want to create more "types" I can simply add the ways of processing each type in a database rather than having to hard code a new check or class into my Java file and recompiling/deploying.
I've read this StackOverFlow post: Convert String to Code , but as the comments point out, there is a significant risk associated with just having arbitrary code ran.
Ideally, I'd like to have some Java method that is loaded externally that has a parameter for the JSON data, and then it does it's own checks and processing and returns a value.
Is there any safe and (somewhat) easy way to do this? Perhaps parsing string as java code isn't the right idea (maybe doing some external class loading would be smarter), but I wanted to ask if anyone has any ideas regarding ways to do this.