[fasterxml]json 도구 류

코드 를 직접 붙 여서 다음 에 사용 하기 편 합 니 다.
/**
 * json    
 * 

* Created by xlch at 2018/6/26 */ public class JsonUtil { private JsonUtil() { } private static final Logger LOGGER = LoggerFactory.getLogger(JsonUtil.class); private static final ObjectMapper mapper = new ObjectMapper(); static { // null : mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // : mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); // mapper.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE); } public static T json2Object(String source, Class classType) { try { return mapper.readValue(source, classType); } catch (IOException e) { LOGGER.debug("exception is ", e); throw new VastioException("json "); } } public static List json2ObjectList(String source, Class classType) { JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, classType); try { return mapper.readValue(source, javaType); } catch (IOException e) { LOGGER.debug("exception is ", e); throw new VastioException("json list "); } } public static String objects2Json(T source) { try { return mapper.writeValueAsString(source); } catch (JsonProcessingException e) { LOGGER.debug("exception is {}", e); throw new VastioException("json "); } } }


좋은 웹페이지 즐겨찾기