First line creates a new Restaurant object. second line also creates a new Restaurant object but using a JSON string, you need Jackson library for this task. You don't need first line if your requirement is only to create an object.

lets say your Restaurant class looks like this.

class Restaurant {
   private String id;
   private String name;

   //getters and setters
}

and you have a JSON look likes this.

String json = "{ \"id\" : \"1\", \"name\" : \"My Restaurant\" }";

Then you can create Restaurant object using second line

Restaurant restaurant = objectMapper.readValue(json, Restaurant.class);

after that you can read json values from restaurant object.

System.out.println(restaurant.getName());

output:

My Restaurant
Answer from Vimukthi on Stack Overflow
🌐
Baeldung
baeldung.com › home › json › jackson › intro to the jackson objectmapper
Intro to the Jackson ObjectMapper | Baeldung
December 9, 2025 - This tutorial focuses on understanding the Jackson ObjectMapper class and how to serialize Java objects into JSON and deserialize JSON string into Java objects.
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-objectmapper.html
Jackson ObjectMapper
It is possible to use the Jackson ObjectMapper to convert a Java object to a JsonNode with the JsonNode being a JSON representation of the Java object converted. You convert a Java object to a JsonNode via the Jackson ObjectMapper valueToTree() method. Here is an example of converting a Java object to a JsonNode using the ObjectMapper valueToTree() method:
🌐
TutorialsPoint
tutorialspoint.com › jackson › jackson_objectmapper.htm
Jackson - ObjectMapper Class
package com.tutorialspoint; import java.io.IOException; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; public class JacksonTester { public static void main(String args[]){ ObjectMapper mapper = new ObjectMapper(); String jsonString = "{\"name\":\"Mahesh\", \"age\":21}"; //map json to student try{ Student student = mapper.readValue(jsonString, Student.class); System.out.println(student); jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(student); System.ou
🌐
Medium
medium.com › @salvipriya97 › java-objectmapper-explained-c33cdc4876d1
Java ObjectMapper explained. In Java, an object mapper is a tool… | by Priya Salvi | Medium
April 21, 2024 - In this example, we use the readValue() method of ObjectMapper to convert the JSON string into a Person object. Jackson automatically maps the fields in the JSON to the corresponding fields in the Person class.
🌐
Medium
medium.com › @salvipriya97 › objectmapper-and-its-methods-examples-in-java-4a4cab75cb6b
ObjectMapper and its methods examples in Java | by Priya Salvi | Medium
June 25, 2024 - Purpose: Serializes a Java object into a JSON string. ... import com.fasterxml.jackson.databind.ObjectMapper; public class Main { public static void main(String[] args) { Person person = new Person("John", 30); ObjectMapper objectMapper = new ...
🌐
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › 6-5 › javadoc › com › fasterxml › jackson › databind › ObjectMapper.html
ObjectMapper (The Adobe AEM Quickstart and Web Application.)
This means that it can serialize all standard JDK types, as well as regular Java Beans (based on method names and Jackson-specific annotations), but does not support JAXB annotations. ... Constructs instance that uses specified JsonFactory for constructing necessary JsonParsers and/or JsonGenerators. public ObjectMapper(JsonFactory jf, DefaultSerializerProvider sp, DefaultDeserializationContext dc)
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java › json › jackson
Jackson ObjectMapper - Examples Java Code Geeks - 2026
June 19, 2020 - In this example, we will learn about the ObjectMapper class from Jackson and its capabilities to serialize POJOs(Plain Old Java Objects) into JSON strings
Find elsewhere
🌐
DEV Community
dev.to › sadiul_hakim › jackson-tutorial-comprehensive-guide-with-examples-2gdj
Jackson Tutorial: Comprehensive Guide with Examples - DEV Community
September 18, 2025 - import java.io.InputStream; import ... = new ObjectMapper(); try (InputStream inputStream = getClass().getResourceAsStream("/data.json")) { MyObject obj = mapper.readValue(inputStream, MyObject.class); }...
🌐
GitHub
github.com › joansmith › jackson-databind › blob › master › src › main › java › com › fasterxml › jackson › databind › ObjectMapper.java
jackson-databind/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java at master · joansmith/jackson-databind
public class ObjectMapper · extends ObjectCodec · implements Versioned, java.io.Serializable // as of 2.1 · { private static final long serialVersionUID = 1L; · /* /********************************************************** /* Helper classes, enums ·
Author   joansmith
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.7 › com › fasterxml › jackson › databind › ObjectMapper.html
ObjectMapper (jackson-databind 2.7.0 API)
protected ObjectReader _newReader(DeserializationConfig config, JavaType valueType, Object valueToUpdate, FormatSchema schema, InjectableValues injectableValues) Factory method sub-classes must override, to produce ObjectReader instances of proper sub-type ... Method that will return version information stored in and read from jar that contains this class. ... Method for registering a module that can extend functionality provided by this mapper; for example, by adding providers for custom serializers and deserializers.
🌐
Spring Framework Guru
springframework.guru › home › how to the jackson object mapper with json
How to The Jackson Object Mapper with JSON - Spring Framework Guru
October 22, 2024 - We can examine the execution in the IntelliJ debugger to see the Jackson ObjectMapper mapped the JSON string to a Java LinkedHashMap: JsonNode is a Jackson type used to represent JSON data as a Java type. JsonNode is an immutable object graph generated from JSON. The following is an example of reading JSON into the JsonNode type.
🌐
javaspring
javaspring.net › blog › java-objectmapper
Mastering Java ObjectMapper: A Comprehensive Guide — javaspring.net
In this example, we create a Person object, instantiate an ObjectMapper, and then use the writeValueAsString method to convert the Person object into a JSON string. Deserialization is the process of converting a JSON string into a Java object.
🌐
Oracle
blogs.oracle.com › javamagazine › java-json-serialization-jackson
Looking for a fast, efficient way to serialize and share Java objects? Try Jackson.
What happened? Recall that ObjectMapper expects getters for serialization—and it wants them to conform to the JavaBeans get/setFoo() convention.
🌐
iO Flood
ioflood.com › blog › objectmapper
ObjectMapper in Java: Conversion with the Jackson API
March 5, 2024 - In this example, we first define a simple Employee class with two properties: name and age. We then create an instance of this class, set some values, and finally use ObjectMapper’s writeValueAsString method to convert this object into a JSON ...
🌐
Javadoc.io
javadoc.io › doc › com.fasterxml.jackson.core › jackson-databind › 2.3.1 › com › fasterxml › jackson › databind › ObjectMapper.html
ObjectMapper - jackson-databind 2.3.1 javadoc
https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind · Current version 2.3.1 · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.3.1 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/2.3.1/package-list ·
🌐
Mkyong
mkyong.com › home › java › convert java objects to json with jackson
Convert Java Objects to JSON with Jackson - Mkyong.com
April 24, 2024 - package com.mkyong.json.jackson.tips; ... RuntimeException(e); } } } ... This example uses Jackson to convert a Java object Person to a JSON string and write it in a file named person.json....
🌐
Reflectoring
reflectoring.io › jackson
All You Need To Know About JSON Parsing With Jackson
July 15, 2022 - That is done by removing the “get” ... to lowercase. For example, say we have a JSON field called name, ObjectMapper will match it with the getter getName() and the setter setName() in the POJO....
🌐
Readthedocs
jse.readthedocs.io › en › latest › utils › jackson › jacksonObjectMapper.html
Jackson ObjectMapper — Java Repositories 1.0 documentation
String json = "{ \"color\" : \"Black\", \"type\" : \"BMW\" }"; ObjectMapper mapper = new ObjectMapper(); SimpleModule module = new SimpleModule("CustomCarDeserializer", new Version(1, 0, 0, null, null, null)); module.addDeserializer(Car.class, new CustomCarDeserializer()); mapper.registerM...
🌐
Studytonight
studytonight.com › java-examples › jackson-objectmapper
Jackson ObjectMapper - Studytonight
August 6, 2021 - We can copy the contents of a JSON file into a Java string and create an object from this string. We will again use the readValue() method of the ObjectMapper class.