From 04866143c6c590f83b0e0ecd95bd9c2bc1ba7220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=8A=B9=EC=A7=84?= Date: Mon, 25 Sep 2023 01:08:10 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20client=20=EB=B3=84=20objectmapper=20?= =?UTF-8?q?=EB=B6=84=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/config/mapper/WebConfiguration.java | 3 ++- .../domain/path/client/SearchCarPathClient.java | 7 ++----- .../domain/path/client/SearchPedPathClient.java | 7 ++----- .../domain/place/client/SurroundPlaceClient.java | 5 ++--- .../plan/client/SearchDestinationClient.java | 10 +++------- .../backend/global/client/KakaoMapClient.java | 15 ++++++++++++--- .../backend/global/client/NaverMapClient.java | 13 ++++++++----- .../twtw/backend/global/client/TmapClient.java | 14 +++++++++++--- 8 files changed, 42 insertions(+), 32 deletions(-) diff --git a/backend/src/main/java/com/twtw/backend/config/mapper/WebConfiguration.java b/backend/src/main/java/com/twtw/backend/config/mapper/WebConfiguration.java index f35ef59e..062a7964 100644 --- a/backend/src/main/java/com/twtw/backend/config/mapper/WebConfiguration.java +++ b/backend/src/main/java/com/twtw/backend/config/mapper/WebConfiguration.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.SerializationFeature; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; @@ -25,6 +26,6 @@ private ObjectMapper objectMapper() { .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true) - .setPropertyNamingStrategy(new CompositePropertyNamingStrategy()); + .setPropertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE); } } diff --git a/backend/src/main/java/com/twtw/backend/domain/path/client/SearchCarPathClient.java b/backend/src/main/java/com/twtw/backend/domain/path/client/SearchCarPathClient.java index 066e37d0..e1629f88 100644 --- a/backend/src/main/java/com/twtw/backend/domain/path/client/SearchCarPathClient.java +++ b/backend/src/main/java/com/twtw/backend/domain/path/client/SearchCarPathClient.java @@ -1,12 +1,10 @@ package com.twtw.backend.domain.path.client; -import com.fasterxml.jackson.databind.ObjectMapper; import com.twtw.backend.domain.path.dto.client.car.SearchCarPathRequest; import com.twtw.backend.domain.path.dto.client.car.SearchCarPathResponse; import com.twtw.backend.global.client.NaverMapClient; import com.twtw.backend.global.exception.WebClientResponseException; import com.twtw.backend.global.properties.NaverProperties; - import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; @@ -20,9 +18,8 @@ public class SearchCarPathClient extends NaverMapClient { private final WebClient webClient; - public SearchCarPathClient( - final ObjectMapper objectMapper, final NaverProperties naverProperties) { - super(objectMapper, naverProperties); + public SearchCarPathClient(final NaverProperties naverProperties) { + super(naverProperties); this.webClient = generateWebClient(); } diff --git a/backend/src/main/java/com/twtw/backend/domain/path/client/SearchPedPathClient.java b/backend/src/main/java/com/twtw/backend/domain/path/client/SearchPedPathClient.java index 076458e3..30467a9e 100644 --- a/backend/src/main/java/com/twtw/backend/domain/path/client/SearchPedPathClient.java +++ b/backend/src/main/java/com/twtw/backend/domain/path/client/SearchPedPathClient.java @@ -1,12 +1,10 @@ package com.twtw.backend.domain.path.client; -import com.fasterxml.jackson.databind.ObjectMapper; import com.twtw.backend.domain.path.dto.client.ped.SearchPedPathRequest; import com.twtw.backend.domain.path.dto.client.ped.SearchPedPathResponse; import com.twtw.backend.global.client.TmapClient; import com.twtw.backend.global.exception.WebClientResponseException; import com.twtw.backend.global.properties.TmapProperties; - import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; @@ -20,9 +18,8 @@ public class SearchPedPathClient extends TmapClient implements MapClient { private static final Integer NO_LIMIT = -1; - private final ObjectMapper objectMapper; protected final KakaoProperties kakaoProperties; protected WebClient generateWebClient() { + final ObjectMapper objectMapper = objectMapper(); + final ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() .codecs( @@ -42,4 +44,11 @@ protected WebClient generateWebClient() { .exchangeStrategies(exchangeStrategies) .build(); } + + private ObjectMapper objectMapper() { + return new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true) + .setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); + } } diff --git a/backend/src/main/java/com/twtw/backend/global/client/NaverMapClient.java b/backend/src/main/java/com/twtw/backend/global/client/NaverMapClient.java index 981b8d4b..61945ce2 100644 --- a/backend/src/main/java/com/twtw/backend/global/client/NaverMapClient.java +++ b/backend/src/main/java/com/twtw/backend/global/client/NaverMapClient.java @@ -4,11 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.SerializationFeature; -import com.twtw.backend.config.mapper.CompositePropertyNamingStrategy; import com.twtw.backend.global.properties.NaverProperties; - import lombok.RequiredArgsConstructor; - import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.web.reactive.function.client.ExchangeStrategies; @@ -17,11 +14,10 @@ @RequiredArgsConstructor public abstract class NaverMapClient implements MapClient { private static final Integer NO_LIMIT = -1; - private final ObjectMapper objectMapper; protected final NaverProperties naverProperties; protected WebClient generateWebClient() { - objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); + final ObjectMapper objectMapper = objectMapper(); final ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() @@ -46,4 +42,11 @@ protected WebClient generateWebClient() { .exchangeStrategies(exchangeStrategies) .build(); } + + private ObjectMapper objectMapper() { + return new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true) + .setPropertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE); + } } diff --git a/backend/src/main/java/com/twtw/backend/global/client/TmapClient.java b/backend/src/main/java/com/twtw/backend/global/client/TmapClient.java index 3d7c968d..97693707 100644 --- a/backend/src/main/java/com/twtw/backend/global/client/TmapClient.java +++ b/backend/src/main/java/com/twtw/backend/global/client/TmapClient.java @@ -1,11 +1,11 @@ package com.twtw.backend.global.client; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.SerializationFeature; import com.twtw.backend.global.properties.TmapProperties; - import lombok.RequiredArgsConstructor; - import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.web.reactive.function.client.ExchangeStrategies; @@ -15,10 +15,11 @@ public abstract class TmapClient implements MapClient { private static final Integer NO_LIMIT = -1; private static final String APP_KEY_HEADER = "appKey"; - private final ObjectMapper objectMapper; protected final TmapProperties tmapProperties; protected WebClient generateWebClient() { + final ObjectMapper objectMapper = objectMapper(); + final ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() .codecs( @@ -41,4 +42,11 @@ protected WebClient generateWebClient() { .exchangeStrategies(exchangeStrategies) .build(); } + + private ObjectMapper objectMapper() { + return new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true) + .setPropertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE); + } }