Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding UncheckedObjectReader/-Writer (or Safe-) #779

Closed
cowtowncoder opened this issue May 3, 2015 · 4 comments
Closed

Consider adding UncheckedObjectReader/-Writer (or Safe-) #779

cowtowncoder opened this issue May 3, 2015 · 4 comments
Labels

Comments

@cowtowncoder
Copy link
Member

(note: inspired by #778)

Given that use of checked exceptions can be problematic for some use cases, perhaps it would make sense to implement an ObjectMapper-like abstraction that can wrap an actual ObjectMapper, but expose set of methods that do NOT throw IOException (and subtypes), but rather wrap such exceptions as RuntimeExceptions.

Actually, since it is ok for sub-class to remove exceptions from signature, this could just be a sub-class of ObjectMapper, for improved compatibility (cast as ObjectMapper there is no benefit wrt exception declarations, but it would work).
However, implementation should still use delegation model instead of sub-classing, to support use with other ObjectMapper subtypes, like XmlMapper.

This is a half-baked idea at this point, so feel free to add comments for improvements, or for/against the idea. Note however that API definition of ObjectMapper itself is not under discussion for Jackson 2.x, at least; and even for 3.x change to unchecked exceptions would be a major change and would need separate discussion.

@phraktle
Copy link

Having an API with unchecked exceptions would be very useful with Java8 lambdas, so +1 for this.

One note: subclassing may impose a performance hit on method dispatch (formerly monomorphic call-sites may become polymorphic). So perhaps delegation without subclassing might be appropriate.

@cowtowncoder
Copy link
Member Author

Having thought bit more about this, I think it would make more sense to expose unchecked/"safe" variants of ObjectReader / ObjectWriter. Benefits there are:

  1. Since these are not sub-classed by other modules, we could just directly sub-class instances, AND they would work with other mapper variants (like XmlMapper or AvroMapper)
  2. Access could/should be via "mutant factory", to allow switching to "safe" instance as needed, even from "unsafe" (checked exceptions exposing) instance
  3. APIs are smaller so this is bit less work as well

@cowtowncoder cowtowncoder changed the title Consider adding "UncheckedObjectMapper" (aka "SafeObjectMapper") Consider adding UncheckedObjectReader/-Writer (or Safe-) Mar 31, 2017
@cowtowncoder cowtowncoder added 3.x and removed 2.9 labels Mar 31, 2017
@cowtowncoder
Copy link
Member Author

While no work has started here, I think that work towards builder-based ObjectMapper construction should help a lot here. That should allow easy(-ier) and cheap(er) wrapper-based approach, so that regular mapper (of format-specific type, if need be) can be wrapped, without requiring sub-classing.

Or, alternatively, if sub-classing seems desireable, should be much easier to pull off as-well.

@cowtowncoder
Copy link
Member Author

This will actually be resolved by quite a different approach: just make exceptions unchecked in 3.x:

https://github.com/FasterXML/jackson-future-ideas/wiki/JSTEP-4

Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants