Java Json to Object jsonToObject(String json, Class toValueType)

Here you can find the source of jsonToObject(String json, Class toValueType)

Description

json To Object

License

Apache License

Declaration

public static <T> T jsonToObject(String json, Class<T> toValueType) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.fasterxml.jackson.annotation.JsonInclude.Include;

import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    private static ObjectMapper objectMapper = new ObjectMapper().setSerializationInclusion(Include.NON_NULL);

    public static <T> T jsonToObject(String json, Class<T> toValueType) {
        if (json == null) {
            return null;
        }/*www .  j  a v  a 2  s. c o  m*/
        try {
            return objectMapper.readValue(json, toValueType);
        } catch (Exception e) {
            throw new RuntimeException("json to object failed :" + e.getMessage());
        }
    }
}

Related

  1. jsonToList(String json, Class parametrized, Class... parameterClasses)
  2. jsonToList(String jsonStr, TypeReference valueTypeRef)
  3. jsonToMap(String src)
  4. jsonToObj(String json, Class clazz)
  5. jsonToObj(String json, Class valueType)
  6. jsonToObject(String jsonString, Class classOfT)
  7. jsonToPojo(String jsonData, Class beanType)
  8. parse(String jsonLine)
  9. readValue(String jsonStr, Class valueType)