公司例子使用了ObjectMapper()這個物件
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.JsonGenerationException;
public static Map<String, String> BeanToMap( Object bean ) throws JsonGenerationException, JsonMappingException, IOException {
if (bean != null) {
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(bean);
Map<String, String> requestMap = mapper.readValue(json, Map.class);
return requestMap;
} else {
return null;
}
}
全站熱搜
留言列表