Skip to content

Change parent type of JsonProcessingException to be RuntimeException #2177

Closed

Description

@cowtowncoder

(NOTE: part of bigger set of changes, see https://github.com/FasterXML/jackson-future-ideas/wiki/JSTEP-4)

Although choice of JsonProcessingException to extend IOException made sense originally (I think), later developments -- in particular, Java 8 Streams and functional approach in general -- have made use of checked exceptions cumbersome for many use cases.
But due to backwards compatibility concerns, change of base exception type has not been possible within 2.x releases.

Now that we are working on 3.0, however, we can make this change. Compared to alternative of providing alternate subtypes of ObjectMapper, ObjectReader and/or ObjectWriter (ones that do not declare checked exceptions for methods), this leads to simpler API.
For 2.x we may still consider simpler work-arounds (maybe convenience wrappers), but with 3.0 let's rebase.

Note, too, that this will help use of Jackson for some specific cases like serialization of this from toString() (and with #2176).

Activity

  1. added
    3.x
    on Nov 7, 2018
  2. added
    most-wanted
    on Sep 2, 2020
  3. cowtowncoder commented on Jan 12, 2021

    @cowtowncoder
    MemberAuthor

    Note: actual change is being done via jackson-core, as:

    FasterXML/jackson-core#661

    and I have a branch with mostly complete changes. However, coordination with all modules is required so while this effort is finally active again, it may take a week or two.

  4. added 5 commits that reference this issue on Jan 12, 2021
  5. cowtowncoder commented on Jan 19, 2021

    @cowtowncoder
    MemberAuthor

    A lot of work done, on exp/jstep-4-for-3.0 branches of:

    • jackson-core, jackson-databind (core packages; annotations not affected)
    • All dataformats (jackson-dataformats-binary, jackson-dataformats-text, jackson-dataformat-xml)
    • jackson-jr
    • Some datatypes (jackson-datatypes-collections, jackson-datatype-joda)
    • Main modules (jackson-modules-base, jackson-modules-java8)

    and just sent an email to jackson-dev.

    Next steps:

    • Continue work on modules (jackson-datatypes-misc, jackson-jaxrs-providers, especially)
    • Coordinate with Kotlin and Scala module authors

    and planning on merging the changes tomorrow, January 19th 2021, if all goes well.

  6. added 2 commits that reference this issue on Jan 20, 2021
  7. cowtowncoder commented on Jan 23, 2021

    @cowtowncoder
    MemberAuthor

    The core change has been completed; continuing with related clean up.

    Noteworthy related changes:

    • Addition of replacement exception types:
      • JsonProcessingException -> JacksonException (added in 2.12)
      • JsonParseException -> StreamReadException (added in 2.10)
      • JsonGenerationException -> StreamWriteException (added in 2.13)
      • JsonMappingException -> DatabindException (added in 2.13)

    In all of above cases the new exception type -- planned to replace original one in 3.0 -- will be new super-class so that:

    1. Code that catches exceptions CAN (and eventually SHOULD) start using it, even in 2.x (since existing code that throws either old or new type would still be compatible)
    2. Code that throws exceptions CANNOT start replacing type since existing code that catches old exceptions would not catch new type

    To prevent (2), new types are added as abstract types in 2.x and become concrete only in 3.0.

  8. added this to the 3.0.0 milestone on Jan 29, 2021
  9. cowtowncoder commented on Jan 29, 2021

    @cowtowncoder
    MemberAuthor

    Completed; may work on demoting some aspects of DatabindException (logical location) down to JacksonException but there's separate issue for that already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.xmost-wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions