ObjectMapper ignores second SimpleModule registered

16 Views Asked by At

I've a very upsetting time with java ObjectMapper which simple ignores my SimpleModule registration because there is another one registred.

the code is more or less like this

   @Autowired
   public void setObjectMapper(@NonNull final ObjectMapper om, @NonNull @Qualifier("my-deserializer") final Module module) throws IOException {
      final String finalJson = "{ \"exported\":false,  \"ID_UNIDADE_IMOB\": 472972 }";

      om.configure(MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS, false)
        .registerModule(new JavaTimeModule())
        .registerModule(new SimpleModule().setDeserializerModifier(new BeanDeserializerModifier() {
           @Override
           public JsonDeserializer<?> modifyDeserializer(DeserializationConfig config, BeanDescription beanDescription, JsonDeserializer<?> originalDeserializer) {
              return new ObjectMapperConfiguration.CustomAnnotationsDeserializer(originalDeserializer, beanDescription);
           }
        }))//remove the one above
        .registerModule(module)
        .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
        .configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, false)
        .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);

      System.out.println(om.readValue(finalJson, new TypeReference<Map<String, Long>>() {
      }));


   }

this code won't run because exported = false and i'm trying to parse it into a Map<String,Long>, that should be the normal objectmapper behavior if werent for MY-MODULE that is supposed to deserialize anything that isn't a number into NULL

my module works and even this code will work if i remove the line indicated in the comments. so i can't stop thinking that objectmappere keeps ignoring the duplicate module.

is there any way to force the module being added?

0

There are 0 best solutions below