2.12.7 to 2.13.5 Behavioural Change

63 views
Skip to first unread message

Martin Samm

unread,
Jun 27, 2023, 3:22:40 PM6/27/23
to jackson-user
So, i have an issue i'm struggling to resolve. I have a service making a REST call to another service. Using jackson 2.12.7 all's well. Upgrading to jackson 2.13.5 the same code, config etc i'm getting this error:

Could not resolve subtype of [simple type, class com.rapid7.platform.ipims.domain.PlatformUser]: missing type id property '@class'

The PlatformUser class is a straight forward POJO (and again unchanged) with the following props:

private String userId;
private Customer customer;
private String email;
private String oktaUserId;
private Long createdTime;
private Long lastLoginTime;
private boolean multiCustomer = false;
private boolean externalIdp;
private Map<String, String> userProperties = new HashMap<>();


We're using a Mixin to avoid deserializing userProperties Map.

Our objectMapper is setup like this:

private ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(
ObjectMapper.DefaultTyping.NON_FINAL,
JsonTypeInfo.As.PROPERTY
);
mapper.registerModule(new CoreJackson2Module());
mapper.registerModule(new WebJackson2Module());
mapper.registerModule(new WebServletJackson2Module());
mapper.registerModule(new WebServerJackson2Module());
mapper.registerModule(new Saml2Jackson2Module());
mapper.registerModules(new Saml2Jackson2Module());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// handle Java 8 Datetime with JSR-310
mapper.registerModule(new JavaTimeModule());
mapper.addMixIn(PlatformUser.class, PlatformUserMixin.class);
mapper.addMixIn(MapSession.class, MapSessionMixin.class);
return mapper;
}


Debugging through the code i can see the objectmapper is wired in fine and that the objectMapper is setting it's valueType to a SimpleType[simple type, class PlatformUser] so things seem setup correctly but at some point something odd is happening and an AsPropertyTypeDeserializer is used and triggers the above exception (seems to be expecting the JSON to contain an @class definition/declaration, which was unnecessary previously).

So, can anyone help point me in the right direction?

Thanks alot.






Joo Hyuk Kim (김주혁)

unread,
Jun 28, 2023, 5:27:09 AM6/28/23
to jackson-user

This is not a solution, but beware that starting from Jackson 2.10, `ObjectMapper.enableDefaultTyping` has been deprecated and `ObjectMapper.enableDefaultTyping` internally calls `activateDefaultTyping()`.

Tatu Saloranta

unread,
Jul 4, 2023, 12:20:48 AM7/4/23
to jackso...@googlegroups.com
^^^ remove this, or set to true, for debugging. I can't believe how
often this setting hides real problems.
While it may be useful in production, it's almost always bad idea when testing.

> // handle Java 8 Datetime with JSR-310
> mapper.registerModule(new JavaTimeModule());
> mapper.addMixIn(PlatformUser.class, PlatformUserMixin.class);
> mapper.addMixIn(MapSession.class, MapSessionMixin.class);
> return mapper;
> }
>
>
> Debugging through the code i can see the objectmapper is wired in fine and that the objectMapper is setting it's valueType to a SimpleType[simple type, class PlatformUser] so things seem setup correctly but at some point something odd is happening and an AsPropertyTypeDeserializer is used and triggers the above exception (seems to be expecting the JSON to contain an @class definition/declaration, which was unnecessary previously).
>
> So, can anyone help point me in the right direction?

One thing to keep in mind is that it is possible there was a bug in
2.12 and earlier that did not catch a real problem with input data.
Use of type identifier is not, for example, optional (unless type has
"defaultImpl").

But you are also not including much of actually relevant information like:

1. Actual code used to read/write values
2. JSON being read (if reproduction does not write what is being read)

which is needed to actually reproduce the problem. Verbal description
and POJO definitions are not sufficient on their own.

-+ Tatu +-
Reply all
Reply to author
Forward
0 new messages