If you need to convert JSON to a Java Object, then you can do one of the following:

Option 1 – Using Gson

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import com.google.gson.Gson;

public class SimpleTesting {
    public static void main(String[] args) throws InterruptedException {
        String json = """
            {
                "firstName" : "Jane",
                "lastName" : "Doe",
                "dateOfBirth" : "1973-04-29",
                "address" : "81 Hype",
                "city" : "New York",
                "contact" : "0123456789"
            }
            """;
        Student data = new Gson().fromJson(json, Student.class);

        System.out.println(data.getFirstName());
        System.out.println(data.getLastName());
        System.out.println(data.getCity());
    }
}

class Student {
    private String firstName;
    private String lastName;
    private String dateOfBirth;
    private String address;
    private String city;
    private String contact;

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getDateOfBirth() {
        return dateOfBirth;
    }
    public void setDateOfBirth(String dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getContact() {
        return contact;
    }
    public void setContact(String contact) {
        this.contact = contact;
    }
}

Option 2 – Using Jackson

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.io.File;
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class SimpleTesting {
    public static void main(String[] args) throws InterruptedException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        try {
            Student student = mapper.readValue(new File("json-file.json"), Student.class);

            System.out.println("First Name: "+student.getFirstName());
            System.out.println("Last Name: "+student.getLastName());
            System.out.println("City: "+student.getCity());
            System.out.println("Address: "+student.getAddress());
            System.out.println("Contact: "+student.getContact());
            System.out.println("Date of Birth: "+student.getDateOfBirth());
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

class Student {
    private String firstName;
    private String lastName;
    private String dateOfBirth;
    private String address;
    private String city;
    private String contact;

    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getDateOfBirth() {
        return dateOfBirth;
    }
    public void setDateOfBirth(String dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getContact() {
        return contact;
    }
    public void setContact(String contact) {
        this.contact = contact;
    }
}