-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ObjectMapper 와 JsonView 통합
- Loading branch information
Showing
2 changed files
with
13 additions
and
19 deletions.
There are no files selected for viewing
14 changes: 13 additions & 1 deletion
14
mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
package webmvc.org.springframework.web.servlet.view; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import java.util.Map; | ||
import web.org.springframework.http.MediaType; | ||
|
||
public class JsonView implements View { | ||
|
||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Override | ||
public void render(final Map<String, ?> model, final HttpServletRequest request, HttpServletResponse response) | ||
throws Exception { | ||
final String body = JsonWriterObjectMapper.writeJson(model); | ||
final String body = writeJson(model); | ||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); | ||
response.getWriter().write(body); | ||
} | ||
|
||
private String writeJson(final Map<String, ?> objects) { | ||
try { | ||
return objectMapper.writeValueAsString(objects); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException("Json 객체 변환 과정에서 예외가 발생했습니다."); | ||
} | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
mvc/src/main/java/webmvc/org/springframework/web/servlet/view/JsonWriterObjectMapper.java
This file was deleted.
Oops, something went wrong.