herdsothom
herdsothom

Reputation: 137

Jackson ObjectMapper - fail on "null" as JSON string

Is it possible to make ObjectMapper fail when "null" is the entire string that is passed in?

The below code returns null, rather than throwing an exception:

objectMapper.readValue("null", MyModel.class);

I have tried the following configurations, with no luck:

.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, true)
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true)
.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, true);

Upvotes: 1

Views: 882

Answers (1)

Roman
Roman

Reputation: 179

Jackson doesnt even try to deserialize "null" values, so the only way is to sanitize input before mapping

Upvotes: 1

Related Questions