Skip to main content
deleted 59 characters in body
Source Link
djm.im
  • 3.3k
  • 4
  • 32
  • 47

I am using Springboot 2.0.6 and for some reason, the app yml changes did not work. And also I had more requirements.

I tried creating ObjectMapper and marking it as Primary but spring boot complained that I already have jacksonObjectMapper as marked Primary!!

So this is what I did. I made changes to the internal mapper.

My Serializer and Deserializer are special - they deal with 'dd/MM/YYYY'; and while de-serializing - it tries its best to use 3-4 popular format to make sure I have some LocalDate.

@Autowired  ObjectMapper mapper;  @PostConstruct  public ObjectMapper configureMapper() {   mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);   mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);   mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);   mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);   mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, true);   mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);   SimpleModule module = new SimpleModule();   module.addDeserializer(LocalDate.class, new LocalDateDeserializer());   module.addSerializer(LocalDate.class, new LocalDateSerializer());   mapper.registerModule(module);   return mapper;  } 

I am using Springboot 2.0.6 and for some reason the app yml changes did not work. And also I had more requirements.

I tried creating ObjectMapper and marking it as Primary but spring boot complained that I already have jacksonObjectMapper as marked Primary!!

So this is what I did. I made changes to the internal mapper.

My Serializer and Deserializer are special - they deal with 'dd/MM/YYYY'; and while de-serializing - it tries its best to use 3-4 popular format to make sure I have some LocalDate.

@Autowired  ObjectMapper mapper;  @PostConstruct  public ObjectMapper configureMapper() {   mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);   mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);   mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);   mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);   mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, true);   mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);   SimpleModule module = new SimpleModule();   module.addDeserializer(LocalDate.class, new LocalDateDeserializer());   module.addSerializer(LocalDate.class, new LocalDateSerializer());   mapper.registerModule(module);   return mapper;  } 

I am using Springboot 2.0.6 and for some reason, the app yml changes did not work. And also I had more requirements.

I tried creating ObjectMapper and marking it as Primary but spring boot complained that I already have jacksonObjectMapper as marked Primary!!

So this is what I did. I made changes to the internal mapper.

My Serializer and Deserializer are special - they deal with 'dd/MM/YYYY'; and while de-serializing - it tries its best to use 3-4 popular format to make sure I have some LocalDate.

@Autowired ObjectMapper mapper; @PostConstruct public ObjectMapper configureMapper() { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, true); mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SimpleModule module = new SimpleModule(); module.addDeserializer(LocalDate.class, new LocalDateDeserializer()); module.addSerializer(LocalDate.class, new LocalDateSerializer()); mapper.registerModule(module); return mapper; } 
formatting
Source Link
Kalpesh Soni
  • 7.4k
  • 2
  • 58
  • 64

I am using Springboot 2.0.6 and for some reason the app yml changes did not work. And also I had more requirements.

I tried creating ObjectMapper and marking it as Primary but spring boot complained that I already have jacksonObjectMapper as marked Primary!!

So this is what I did. I made changes to the internal mapper My.

My Serializer and Deserializer are special - they deal with dd'dd/MM/YYYYYYYY'; and while de-serializing - it tries itits best to use 3-4 popular format to make sure I have some LocalDate.

@Autowired ObjectMapper mapper; @PostConstruct public ObjectMapper configureMapper() { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, true); mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SimpleModule module = new SimpleModule(); module.addDeserializer(LocalDate.class, new LocalDateDeserializer()); module.addSerializer(LocalDate.class, new LocalDateSerializer()); mapper.registerModule(module); return mapper; } 

I am using Springboot 2.0.6 and for some reason the app yml changes did not work And also I had more requirements

I tried creating ObjectMapper and marking it as Primary but spring boot complained that I already have jacksonObjectMapper as marked Primary!!

So this is what I did I made changes to the internal mapper My Serializer and Deserializer are special - they deal with dd/MM/YYYY and while de-serializing it tries it best to use 3-4 popular format to make sure I have some LocalDate

@Autowired ObjectMapper mapper; @PostConstruct public ObjectMapper configureMapper() { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, true); mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SimpleModule module = new SimpleModule(); module.addDeserializer(LocalDate.class, new LocalDateDeserializer()); module.addSerializer(LocalDate.class, new LocalDateSerializer()); mapper.registerModule(module); return mapper; } 

I am using Springboot 2.0.6 and for some reason the app yml changes did not work. And also I had more requirements.

I tried creating ObjectMapper and marking it as Primary but spring boot complained that I already have jacksonObjectMapper as marked Primary!!

So this is what I did. I made changes to the internal mapper.

My Serializer and Deserializer are special - they deal with 'dd/MM/YYYY'; and while de-serializing - it tries its best to use 3-4 popular format to make sure I have some LocalDate.

@Autowired ObjectMapper mapper; @PostConstruct public ObjectMapper configureMapper() { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, true); mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SimpleModule module = new SimpleModule(); module.addDeserializer(LocalDate.class, new LocalDateDeserializer()); module.addSerializer(LocalDate.class, new LocalDateSerializer()); mapper.registerModule(module); return mapper; } 
Source Link
Kalpesh Soni
  • 7.4k
  • 2
  • 58
  • 64

I am using Springboot 2.0.6 and for some reason the app yml changes did not work And also I had more requirements

I tried creating ObjectMapper and marking it as Primary but spring boot complained that I already have jacksonObjectMapper as marked Primary!!

So this is what I did I made changes to the internal mapper My Serializer and Deserializer are special - they deal with dd/MM/YYYY and while de-serializing it tries it best to use 3-4 popular format to make sure I have some LocalDate

@Autowired ObjectMapper mapper; @PostConstruct public ObjectMapper configureMapper() { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); mapper.configure(MapperFeature.ALLOW_COERCION_OF_SCALARS, true); mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); SimpleModule module = new SimpleModule(); module.addDeserializer(LocalDate.class, new LocalDateDeserializer()); module.addSerializer(LocalDate.class, new LocalDateSerializer()); mapper.registerModule(module); return mapper; }