ObjectMappingUtils.java 480 B

123456789101112131415161718
  1. package com.lightinit.hsdatashow.common;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import java.io.IOException;
  4. /**
  5. * Created by WangYao on 2018/5/23.
  6. */
  7. public class ObjectMappingUtils {
  8. public static <S, T> T map(S source, Class<T> classType) throws IOException {
  9. ObjectMapper objectMapper = new ObjectMapper();
  10. String jsonString = objectMapper.writeValueAsString(source);
  11. return objectMapper.readValue(jsonString, classType);
  12. }
  13. }