Executing Java code from String safely
<p>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"</p>

<p>My backend system checks the "type" and executes specific Java code based on the type.</p>

<p>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.</p>

<p>I've read this StackOverFlow post: <a href="http://stackoverflow.com/questions/935175/convert-string-to-code">Convert String to code</a> , but as the comments point out, there is a significant risk associated with just having arbitrary code ran.</p>

<p>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.</p>

<p>Is there any <strong>safe</strong> and <strong>(somewhat) easy</strong> 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.</p>
