Feel free to ignore the people saying "don't do that". You know your code and requirements better than we do.
What you're looking for is called "reflection" in java. You can loop over your JSON key/value pairs, then look up the field using reflection, then set the field w/ the value.
This question has a good breakdown on how to do that.
Then use a static initialize block start your import function.
Good luck!
EDIT:
Some example code to show this isn't some crazy, complicated, unreadable horrible, no-good, very-bad idea that only James Gosling should ever attempt. :)
import java.lang.reflect.*;
import net.sf.json.*;
public class Test {
public static String hello = null;
static JSONObject readConfig() {
// fake read a config file
String settings = "{\"hello\": \"world\"}";
JSONObject obj = (JSONObject)JSONSerializer.toJSON(settings);
return obj;
}
static {
// load config into static variables
JSONObject config = Test.readConfig();
for (Object key : config.keySet()) {
String value = config.getString((String)key);
try {
Field field = Test.class.getDeclaredField((String)key);
field.set(null, value);
System.out.println("Set '"+ key +"' to '"+ value +"'.");
} catch (Exception e) {
System.err.println("Could not set unknown prop '"+ key +"' because "+ e +".");
}
}
}
public static void main(String[] args) {}
}
And it running:
$ javac -cp .:/usr/share/java/* Test.java
$ java -cp .:/usr/share/java/* Test
Set 'hello' to 'world'.