Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6579109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:51:26+00:00 2026-05-25T15:51:26+00:00

Jackson’s ObjectMapper#readValue member throws three checked exceptions: IOException JsonParseException JsonMappingException JsonParseException and JsonMappingException extend

  • 0

Jackson’s ObjectMapper#readValue member throws three checked exceptions:

IOException 
JsonParseException 
JsonMappingException

JsonParseException and JsonMappingException extend IOException. I want to wrap the two aforementioned child classes and throw my own custom exceptions, yet, the base class, IOException, being checked, requires me to either catch or throw it also.

It doesn’t make sense for me to throw the IOException up to the calling layer, but, adversely, it’s a smell if I hide it. My original thought was to not catch it and leave it to the caller/run-time exception mechanism to deal with it… yet, I don’t want to have to force the caller to catch or specify.

What does one do in such a situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:51:27+00:00Added an answer on May 25, 2026 at 3:51 pm

    Short answer: if you deal with IO, you deal with IOExceptions. If you don’t deal with IO, then IOExceptions should be turned into unchecked exceptions, because they’re symptoms of buggy code.


    Longer answer:

    readValue always takes a JsonParser, which may be wrapped around IO (e.g. a file or a URL). If you’re dealing with IO, there’s no way around dealing with IOExceptions, and you should either handle them or rethrow/pass them in some way. Anything can happen during IO, and you should be prepared to deal with the exceptions.

    However, if you are sure that your JsonParser instances don’t use IO (e.g. you used JsonFactory#createJsonParser(java.lang.String) to create a JSON parser on a string), you may assume that any IOExceptions you receive are bugs, either in your code or in Jackson. Usually, throwing an unchecked exception is then the proper way to deal with it:

    ObjectMapper om = new ObjectMapper(/* whatever */);
    JsonParser jp = JsonFactory.createJsonParser("{ \"foo\": \"bar\" }");
    try {
        return om.readValue(jp);
    } catch (IOException e) {
        throw new AssertionError("An IOException occurred when this was assumed to be impossible.");
    }
    

    Nota bene: my Java is rusty and I’ve never used Jackson, so consider the above block to be pseudocode.

    In any case, you never need to declare AssertionError in throws, because they’re unchecked exceptions. Everything that’s a subclass of java.lang.RuntimeException or java.lang.Error doesn’t need to be caught or rethrown explicitly. These exceptions are used for problems that are not expected to occur unless you’re dealing with buggy code or when your VM’s host is on fire.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Jackson library's ObjectMapper for deserializing JSON into Java objects. I am
I'm using Jackson 1.6.4 and Java JDK 6. I don't want to use Jackson
I don't like Jackson. I want to use ajax but with Google Gson. So
I use Jackson and want to check that input JSON string doesn't contain duplicated
I want to use jackson json library for a generic method as follows: public
Spring MVC + Jackson converting Java object to/from Json data. I want to validate
In the following Jackson/Java code that serializes objects into JSON, I am getting this:
Is it possible to use Jackson as the serializer/marshaller for JSON data instead of
We're trying to use Jackson 1.5 to take advantage of some of the polymorphic
Is there a way to force Jackson not to put the class name in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.