To convert a JSON string into a Java object, use the ObjectMapper class from the Jackson library. First, include Jackson dependencies in your project. Then, create an instance of ObjectMapper and use its readValue() method to map the JSON string to a Java object. Here’s an example:
import com.fasterxml.jackson.databind.ObjectMapper;
String jsonString = “{\”name\”:\”John\”, \”age\”:30}”;
ObjectMapper objectMapper = new ObjectMapper();
Person person = objectMapper.readValue(jsonString, Person.class);
In this example, Person is a Java class with fields matching the JSON keys. This method simplifies parsing JSON strings into strongly typed Java objects for further use.