logo

Deserialize JSON string into Java object using ObjectMapper.readValue() with Jackson

Java Code Examples for com.fasterxml.jackson.databind.ObjectMapper.readValue()

This method to deserialize JSON string into a Java object.

package simplesolution.dev;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public class ObjectMapperReadValueExamples {

    public static void main(String... args) {
        String data = "[{\"name\":\"Sample JSON Serialization\",\"url\":\"https://simplesolution.dev\"},{\"name\":\"Java Tutorials\",\"url\":\"https://simplesolution.dev/java\"}]";
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            List<Map<String, String>> objectFromJsonString = objectMapper.readValue(data, List.class);
            System.out.println("Object from String: " + objectFromJsonString);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Happy Coding 😊

Tags: