oblac / jodd

Jodd! Lightweight. Java. Zero dependencies. Use what you like.

Home Page:https://jodd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

optional return types for jodd-json

xaph opened this issue · comments

Hello,

do you think about adding optional return types for jodd-json?

Instead of using these nullable return

String test = jsonObject.getString("test");
if(test != null) {
    //do something
}

using optional return is more modern way to handle null

Optional<String> test = jsonObject.getOptionalString("test");
if(test.isPresent()) {
    //do something
}

what about implement these methods?

Yeah, Jodd is old :)

I personally prefer Consumer, e.g.:

json.withStringValue("test", value -> {});

but again, I could add Optional as well. Just not sure about the method name... getStringValue maybe?

more modern

That is not necessarily better and - at least in your example - there is no actual advantage over it. It will only require more memory.

After some thinking, I believe its better not to migrate anything now. Otherwise, the change should be applied all over the code, and that would break the API.