Gson allows for one of the simplest possible solutions. Compared to similar APIs like Jackson or svenson, Gson by default doesn't even need the unused JSON elements to have bindings available in the Java structure. Specific to the question asked, here's a working solution.
import com.google.gson.Gson;
public class Foo
{
static String jsonInput =
"{" +
"\"name\":\"John\"," +
"\"age\":\"20\"," +
"\"address\":\"some address\"," +
"\"someobject\":" +
"{" +
"\"field\":\"value\"" +
"}" +
"}";
String age;
public static void main(String[] args) throws Exception
{
Gson gson = new Gson();
Foo thing = gson.fromJson(jsonInput, Foo.class);
if (thing.age != null)
{
System.out.println("age is " + thing.age);
}
else
{
System.out.println("age element not present or value is null");
}
}
}