Skip to content

Commit

Permalink
Refactor: configure()JsonMapper.builder().configure(...) 로 변경 및…
Browse files Browse the repository at this point in the history
… 적용 위치 이동

- `configure()` Deprecated. Since 2.13 use JsonMapper.builder().configure(...) 에 따라 리팩토링.
- 직렬화, 역직렬화, 매퍼 설정을 Hal 설정 클래스에서 Serialize 설정 클래스로 이동.
  • Loading branch information
shacomiro committed Apr 24, 2024
1 parent a533a28 commit 033df4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import org.springframework.hateoas.server.core.AnnotationLinkRelationProvider;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

@Configuration
public class JacksonHalConfiguration extends AbstractJackson2HttpMessageConverter {
Expand All @@ -23,9 +20,5 @@ public JacksonHalConfiguration(ObjectMapper objectMapper) {
objectMapper.setHandlerInstantiator(
new Jackson2HalModule.HalHandlerInstantiator(
new AnnotationLinkRelationProvider(), CurieProvider.NONE, MessageResolver.DEFAULTS_ONLY));
objectMapper
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package com.shacomiro.nesonnechek.api.global.config.jackson;

import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.shacomiro.nesonnechek.api.global.security.deserializer.SimpleGrantedAuthorityDeserializer;

@Configuration
public class JacksonSerializeConfiguration {

public JacksonSerializeConfiguration(ObjectMapper objectMapper) {
SimpleModule grantedAuthorityDeserializeModule = new SimpleModule()
.addDeserializer(SimpleGrantedAuthority.class, new SimpleGrantedAuthorityDeserializer());
objectMapper.registerModule(grantedAuthorityDeserializeModule);
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
@Bean
public Jackson2ObjectMapperBuilderCustomizer customizer() {
return builder -> builder.deserializerByType(SimpleGrantedAuthority.class, new SimpleGrantedAuthorityDeserializer())
.featuresToEnable(SerializationFeature.INDENT_OUTPUT)
.featuresToEnable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.featuresToEnable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
}
}

0 comments on commit 033df4a

Please sign in to comment.