Here you can find the source of decode(String json, Class
Parameter | Description |
---|---|
json | a parameter |
clazz | a parameter |
public static <T> T decode(String json, Class<T> clazz)
//package com.java2s; //License from project: Apache License import java.io.IOException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { /**/*w w w. j ava 2s. c o m*/ * json decode * @param json * @param clazz * @return clazz * @author sinmetal */ public static <T> T decode(String json, Class<T> clazz) { try { return new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).readValue(json, clazz); } catch (IOException e) { throw new IllegalStateException(e); } } /** * json decode * @param json * @param valueTypeRef * @return clazz * @author sinmetal */ public static <T> T decode(String json, TypeReference<?> valueTypeRef) { try { return new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).readValue(json, valueTypeRef); } catch (IOException e) { throw new IllegalStateException(e); } } }