Skip to content

Commit

Permalink
refactor: ObjectWriter, ObjectReader 로 static 선언
Browse files Browse the repository at this point in the history
  • Loading branch information
Songusika committed Sep 26, 2023
1 parent 8e54dea commit b65c405
Showing 1 changed file with 13 additions and 2 deletions.
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);
}
}

0 comments on commit b65c405

Please sign in to comment.