-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ObjectWriter, ObjectReader 로 static 선언
- Loading branch information
Showing
1 changed file
with
13 additions
and
2 deletions.
There are no files selected for viewing
15 changes: 13 additions & 2 deletions
15
mvc/src/main/java/web/org/springframework/util/HttpRequestBodyConverter.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,14 +1,25 @@ | ||
package web.org.springframework.util; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ObjectReader; | ||
import com.fasterxml.jackson.databind.ObjectWriter; | ||
|
||
public class HttpRequestBodyConverter { | ||
|
||
private static final ObjectReader reader; | ||
private static final ObjectWriter writer; | ||
|
||
static { | ||
final ObjectMapper mapper = new ObjectMapper(); | ||
reader = mapper.reader(); | ||
writer = mapper.writer(); | ||
} | ||
|
||
public static Object serialize(final String json, final Class<?> target) throws Exception { | ||
return new ObjectMapper().readValue(json, target); | ||
return reader.readValue(json, target); | ||
} | ||
|
||
public static String deserialize(final Object object) throws Exception { | ||
return new ObjectMapper().writeValueAsString(object); | ||
return writer.writeValueAsString(object); | ||
} | ||
} |