Java Json to Object deserialize(String json, Class targetType)

Here you can find the source of deserialize(String json, Class targetType)

Description

deserialize

License

Apache License

Declaration

public static <T> T deserialize(String json, Class<T> targetType) 

Method Source Code


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

import java.io.IOException;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static <T> T deserialize(String json, Class<T> targetType) {
        try {//  w  w w.java2s  .c o m
            return objectMapper.readValue(json, targetType);
        } catch (IOException e) {
            throw new IllegalStateException("Failed to convert json to object", e);
        }
    }

    public static <T> T deserialize(String json, JavaType targetType) {
        try {
            return objectMapper.readValue(json, targetType);
        } catch (IOException e) {
            throw new IllegalStateException("Failed to convert json to object", e);
        }
    }
}

Related

  1. decode(String json, Class clazz)
  2. decode(String json, Class clazz)
  3. decodeCommandAsJson(final BsonInput bsonInput)
  4. deserialize(JsonReader reader, Class type)
  5. deserialize(String json, Class clazz)
  6. deserialize(String jsonData, Class typeOfT)
  7. deserializeFromDataNode(JsonParser jp, DeserializationContext ctxt, String propertyName, TypeReference typeReference)
  8. deserializeJson(String content, Class valueType)
  9. json2List(String json, Class beanClass)