Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
com.fasterxml.jackson.databind.ObjectMapper Example
How to use com.fasterxml.jackson.databind.ObjectMapper class?
✍: FYIcenter.com
com.fasterxml.jackson.databind.ObjectMapper class allows you to map a JSON message to a Java class object that matches the JSON property structure.
Here is an example Java program, ObjectMapperTest.java:
// ObjectMapperTest.java
// Copyright (c) FYIcenter.com
import com.fasterxml.jackson.databind.ObjectMapper;
public class ObjectMapperTest {
public static void main(String[] args) throws Exception {
String json
= "{ \"name\": \"John Smith\","
+ " \"married\": false,"
+ " \"age\": 25,"
+ " \"phone\": null"
+ " }";
ObjectMapper mapper = new ObjectMapper();
Person person = mapper.readValue(json, Person.class);
System.out.println(person);
}
public static class Person {
private String name;
private boolean married;
private int age;
private String phone;
public void setName(String name) {
this.name = name;
}
public void setMarried(boolean married) {
this.married = married;
}
public void setAge(int age) {
this.age = age;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String toString(){
return name+", "+age+", "+married+", "+phone;
}
}
}
Run this Java program with 3 Jackson JAR files:
fyicenter$ java -cp jackson-core-2.14.0.jar: \ jackson-databind-2.14.0.jar: \ jackson-annotations-2.14.0.jar \ ObjectMapperTest.java John Smith, 25, false, null
The Java program mapped a JSON message to a Java class object correctly.
⇒ com.fasterxml.jackson.databind.ObjectWriter Example
⇐ Using Jackson Java JSON library
2021-08-11, ∼1285🔥, 0💬
Popular Posts:
What Is mail.jar of JavaMail 1.4? I got the JAR file from javamail-1_4.zip. mail.jar in javamail-1_4...
JDK 17 jdk.jshell.jmod is the JMOD file for JDK 17 JShell tool, which can be invoked by the "jshell"...
JDK 11 java.xml.crypto.jmod is the JMOD file for JDK 11 XML (eXtensible Markup Language) Crypto modu...
JLayer is a library that decodes/plays/converts MPEG 1/2/2.5 Layer 1/2/3 (i.e. MP3) in real time for...
What Is junit-3.8.1.jar? junit-3.8.1.jar is the version 3.8.1 of JUnit JAR library file. JUnit is a ...