Stream API for JsonNullable wrapper - #56
Conversation
|
Any chance of this getting merged? |
|
@NicklasWallgren Hi! As a workaround before merge, you could use lombok's @ExtensionMethod with these methods' implementations. Hope this will help you. Cheers! |
Thanks for the reply. I've created a fork instead. |
|
Thanks for the PR. There is another PR now (#68) which includes some more common methods as well. If that PR is merged, you could recreate this one and add your other methods. |
davidpavlovschi
left a comment
There was a problem hiding this comment.
Triage note: this PR has been superseded on main — since 0.2.8 JsonNullable ships map, flatMap, filter, or, stream and ifPresentOrElse, which covers the core of what this adds. Worse, the two map definitions conflict semantically: the 0.2.8 map applies the mapper whenever isPresent (including an explicit null, so the mapper can see null), while this PR's map guards on isNonNull() and propagates the null state untouched. Changing that now would be a behavioral break for anyone on ≥0.2.8.
What's still genuinely additive here are the null-state helpers that main doesn't have: ofNull(), isNull(), isNonNull(), ifNotNull(). If this were rebased and rescoped to just those, it'd be a reasonable follow-up — with two fixes: (1) the ofMissable javadoc says it returns "UNDEFINED or NULL state" but the implementation (new JsonNullable<>(value, value != null)) actually yields undefined-or-present-non-null — it's Optional.ofNullable semantics, and the name/doc should say so or the method should be dropped; (2) the new test imports junit.framework.TestCase (JUnit 3) — the rest of the suite is on org.junit asserts. Also the change strips the trailing newline from JsonNullable.java.
@DunkanMcLoud if you're still interested, a rebase onto current main scoped to the null-state helpers would make this reviewable; otherwise this can probably be closed as superseded by the 0.2.8 API.
Sometimes it is useful to access DTO's nested data by the means of JDK stream api