Jackson Full Data Binding
Jump to navigation
Jump to search
Internal
Overview
JSON to Java
import com.fasterxml.jackson.databind.ObjectMapper; ObjectMapper om = new ObjectMapper(); Token token = on.readValue(inputStream, Token.class);
This is a generic conversion method, assuming that the JSON content matches the internal structure of the type <T>:
public static <T> T fromJson(String json, Class<? extends T> c) throws JsonConversionException { try { ObjectMapper objectMapper = new ObjectMapper(); return objectMapper.readValue(new ByteArrayInputStream(json.getBytes()), c); } catch (Exception e) { throw new JsonConversionException(e); } }