Skip to content

Commit

Permalink
Swagger + Octet/Stream 문제 상황에 대해 더 명확한 이해를 가지고 이를 녹여낼 수 있는 구조로 코드 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
One-armed-boy committed Mar 10, 2024
1 parent 3988639 commit 851179f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 43 deletions.
43 changes: 0 additions & 43 deletions src/main/java/com/stream/configuration/HttpMsgConverterConfig.java

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/java/com/stream/configuration/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.stream.configuration;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.stream.msgconverter.OctetStreamReadMsgConverter;

@Configuration
public class WebConfig implements WebMvcConfigurer {
private OctetStreamReadMsgConverter octetStreamReadMsgConverter;

@Autowired
public WebConfig(OctetStreamReadMsgConverter octetStreamReadMsgConverter) {
this.octetStreamReadMsgConverter = octetStreamReadMsgConverter;
}

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(octetStreamReadMsgConverter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.stream.msgconverter;

import java.lang.reflect.Type;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;

@Component
public class OctetStreamReadMsgConverter extends AbstractJackson2HttpMessageConverter {
@Autowired
public OctetStreamReadMsgConverter(ObjectMapper objectMapper) {
super(objectMapper, MediaType.APPLICATION_OCTET_STREAM);
}

@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
protected boolean canWrite(MediaType mediaType) {
return false;
}
}

0 comments on commit 851179f

Please sign in to comment.