Anyone heard for a json library supporting java8 Optionals when returning values?
Lets say I have the following json documents:
{
"person" : {
"address" : {
"streetName" : "Moonshtrasse",
"streetNo" : 12
}
}
}
and an empty document
{}
Assuming the get methods in the JSONObject return Optionals, I want to do something like this:
Optional<String> streetName = obj.getJSONObject("person")
.flatMap(person -> person.getJSONObject("address"))
.flatMap(adr -> adr.getString("streetName"));
Instead of checking for null values after every get method.
In the first case this construct would give me an Optional containing the street name and in the second case would give me an empty Optional.