Skip to content

Commit

Permalink
[FEAT] client 별 objectmapper 분기
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Sep 24, 2023
1 parent f6185ed commit 0486614
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,9 +18,8 @@ public class SearchCarPathClient
extends NaverMapClient<SearchCarPathRequest, SearchCarPathResponse> {
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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,9 +18,8 @@ public class SearchPedPathClient extends TmapClient<SearchPedPathRequest, Search

private final WebClient webClient;

public SearchPedPathClient(
final ObjectMapper objectMapper, final TmapProperties tmapProperties) {
super(objectMapper, tmapProperties);
public SearchPedPathClient(final TmapProperties tmapProperties) {
super(tmapProperties);
this.webClient = generateWebClient();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.twtw.backend.domain.place.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.twtw.backend.domain.place.dto.client.SurroundPlaceRequest;
import com.twtw.backend.domain.place.dto.client.SurroundPlaceResponse;
import com.twtw.backend.domain.place.entity.CategoryGroupCode;
Expand All @@ -20,8 +19,8 @@ public class SurroundPlaceClient extends KakaoMapClient<SurroundPlaceRequest, Su
private static final Integer DEFAULT_DISTANCE_RADIUS = 1500;
private final WebClient webClient;

public SurroundPlaceClient(final ObjectMapper objectMapper, final KakaoProperties kakaoProperties) {
super(objectMapper, kakaoProperties);
public SurroundPlaceClient(final KakaoProperties kakaoProperties) {
super(kakaoProperties);
this.webClient = generateWebClient();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.twtw.backend.domain.plan.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.twtw.backend.domain.place.entity.CategoryGroupCode;
import com.twtw.backend.domain.plan.dto.client.SearchDestinationRequest;
import com.twtw.backend.domain.plan.dto.client.SearchDestinationResponse;
import com.twtw.backend.domain.place.entity.CategoryGroupCode;
import com.twtw.backend.global.client.KakaoMapClient;
import com.twtw.backend.global.exception.WebClientResponseException;
import com.twtw.backend.global.properties.KakaoProperties;

import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -24,9 +21,8 @@ public class SearchDestinationClient
private static final Integer DEFAULT_DISTANCE_RADIUS = 20000;
private final WebClient webClient;

public SearchDestinationClient(
final ObjectMapper objectMapper, final KakaoProperties kakaoProperties) {
super(objectMapper, kakaoProperties);
public SearchDestinationClient(final KakaoProperties kakaoProperties) {
super(kakaoProperties);
this.webClient = generateWebClient();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +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.KakaoProperties;

import lombok.RequiredArgsConstructor;

import org.springframework.http.HttpHeaders;
import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
Expand All @@ -14,10 +15,11 @@
@RequiredArgsConstructor
public abstract class KakaoMapClient<T, R> implements MapClient<T, R> {
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(
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,11 +14,10 @@
@RequiredArgsConstructor
public abstract class NaverMapClient<T, R> implements MapClient<T, R> {
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()
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,10 +15,11 @@
public abstract class TmapClient<T, R> implements MapClient<T, R> {
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(
Expand All @@ -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);
}
}

0 comments on commit 0486614

Please sign in to comment.