Blame view

src/main/java/com/batch/util/JsonUtil.java 1016 Bytes
efecfd53   함상기   .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  package com.batch.util;

  

  import org.springframework.stereotype.Component;

  

  import com.fasterxml.jackson.databind.ObjectMapper;

  

  @Component

  public class JsonUtil {

  

      public static String objectToString(Object object) {  	

      	String rtnVal = "";

      	try {

      		ObjectMapper objectMapper = new ObjectMapper();

          	rtnVal = objectMapper.writeValueAsString(object);

      	} catch (Exception e) {

      		e.printStackTrace();

      		rtnVal = "Error";

      	}

          return rtnVal;

      }

  

      public static Object stringToObject(String sJson, Class<?> objClass) {  	

      	Object rtnVal;

      	try {

      		ObjectMapper objectMapper = new ObjectMapper();

          	rtnVal = objectMapper.readValue(sJson, objClass);

      	} catch (Exception e) {

      		e.printStackTrace();

      		rtnVal = "Error";

      	}

          return rtnVal;

      }

  

      public static Object objectToObject(Object object, Class<?> objClass) {

      	return stringToObject(objectToString(object), objClass);

      }

      

  }