|
@ -0,0 +1,20 @@
|
|
|
package com.yihu.jw.utils;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
|
public class EntityUtils {
|
|
|
|
|
|
protected static ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
public static <T> T jsonToEntity(String json,Class<T> target){
|
|
|
T entity = null;
|
|
|
try {
|
|
|
entity = objectMapper.readValue(json,target);
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException("Json字符串转换成【"+target.getName()+"】实体类异常:" + e.getMessage());
|
|
|
}
|
|
|
return entity;
|
|
|
}
|
|
|
|
|
|
}
|