Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jackson Mapper - how to fail on null or empty values

We're using Jackson JSON mapper in our code to de-serialize some configuration objects. We'd like for Jackson to fail on de-serialization when specific fields are missing or empty

The only feature in Jackson to support this behavior is for primitives :

final DeserializationConfig.Feature failOnPremitives = DeserializationConfig.Feature.FAIL_ON_NULL_FOR_PRIMITIVES;

The thing is the fields in question are mainly strings

Any help is highly appreciated

like image 481
Ohad Benita Avatar asked Oct 17 '22 05:10

Ohad Benita


1 Answers

There is an option called: FAIL_ON_NULL_FOR_CREATOR_PARAMETERS.

So I assume it would be accessible at: DeserializationConfig.Feature.FAIL_ON_NULL_FOR_CREATOR_PARAMETERS;

Or in yml:

jackson:
    serialization:
      indent-output: false
    deserialization:
      fail-on-unknown-properties: true
      fail-on-missing-creator-properties: true
      fail-on-null-creator-properties: true

This works on all types, strings, ints, doubles etc..

like image 73
EM-Creations Avatar answered Oct 29 '22 12:10

EM-Creations