Skip to content

IonObjectMapper does not throw JacksonException for some invalid Ion #311

Closed
@popematt

Description

@popematt

In some cases, the IonObjectMapper is not correctly catching and wrapping IonExceptions. For example, given this class:

class FooBar {
    int foo;
    List<Object> bar;
}

When attempting to deserialize invalid Ion, sometimes we get a JsonMappingException, and other times an IonException.

IonObjectMapper mapper = IonObjectMapper.builder().build();

// throws a JsonMappingException
FooBar fb1 = mapper.readValue("{ foo: 1, bar: () ] }", FooBar.class); 
// throws an IonException
FooBar fb1 = mapper.readValue("{ foo: 1, bar: ( ] )  }", FooBar.class); 

Why does this matter? Some other libraries (eg. Ktor, in the JacksonConverter) expect particular exceptions (eg. JsonParseException or JsonMappingException) from an ObjectMapper, and behave in unexpected ways when the IonException leaks through.

I believe the fix for this is to catch and wrap IonException as a JsonParseException in the IonParser.nextToken() method, and I intend to work on a PR for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions