Skip to content

Commit e7cc765

Browse files
committed
update pojo
1 parent 4d69891 commit e7cc765

File tree

2 files changed

+86
-67
lines changed

2 files changed

+86
-67
lines changed

Java-JsonPojo-Example/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
<artifactId>jackson-databind</artifactId>
2222
<version>2.7.5</version>
2323
</dependency>
24+
25+
<dependency>
26+
<groupId>com.fasterxml.jackson.datatype</groupId>
27+
<artifactId>jackson-datatype-jdk8</artifactId>
28+
<version>2.9.0</version>
29+
</dependency>
30+
2431
<dependency>
2532
<groupId>com.google.code.gson</groupId>
2633
<artifactId>gson</artifactId>
Lines changed: 79 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,87 @@
11
package com.howtoprogram.jsonpojo;
22

3+
import java.time.LocalDate;
4+
import java.util.Date;
5+
6+
import com.fasterxml.jackson.annotation.JsonInclude;
7+
8+
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
39

410
public class Book {
511

6-
private Long id;
7-
private String name;
8-
private String author;
9-
10-
11-
public Book() {
12-
super();
13-
}
14-
15-
public Book(Long id, String name, String author) {
16-
super();
17-
this.id = id;
18-
this.name = name;
19-
this.author = author;
20-
}
21-
22-
/**
23-
* @return the id
24-
*/
25-
public Long getId() {
26-
return id;
27-
}
28-
29-
/**
30-
* @param id the id to set
31-
*/
32-
public void setId(Long id) {
33-
this.id = id;
34-
}
35-
36-
/**
37-
* @return the name
38-
*/
39-
public String getName() {
40-
return name;
41-
}
42-
43-
/**
44-
* @param name the name to set
45-
*/
46-
public void setName(String name) {
47-
this.name = name;
48-
}
49-
50-
/**
51-
* @return the author
52-
*/
53-
public String getAuthor() {
54-
return author;
55-
}
56-
57-
/**
58-
* @param author the author to set
59-
*/
60-
public void setAuthor(String author) {
61-
this.author = author;
62-
}
63-
64-
/*
65-
* (non-Javadoc)
66-
*
67-
* @see java.lang.Object#toString()
68-
*/
69-
@Override
70-
public String toString() {
71-
return "Book [id=" + id + ", name=" + name + ", author=" + author + "]";
72-
}
12+
private Long id;
13+
private String name;
14+
private String author;
15+
16+
@JsonInclude(NON_NULL)
17+
private LocalDate pubDate;
18+
@JsonInclude(NON_NULL)
19+
private Date copyrightDate;
20+
21+
public Book() {
22+
super();
23+
}
24+
25+
public Book(Long id, String name, String author) {
26+
super();
27+
this.id = id;
28+
this.name = name;
29+
this.author = author;
30+
}
31+
32+
/**
33+
* @return the id
34+
*/
35+
public Long getId() {
36+
return id;
37+
}
38+
39+
/**
40+
* @param id
41+
* the id to set
42+
*/
43+
public void setId(Long id) {
44+
this.id = id;
45+
}
46+
47+
/**
48+
* @return the name
49+
*/
50+
public String getName() {
51+
return name;
52+
}
53+
54+
/**
55+
* @param name
56+
* the name to set
57+
*/
58+
public void setName(String name) {
59+
this.name = name;
60+
}
61+
62+
/**
63+
* @return the author
64+
*/
65+
public String getAuthor() {
66+
return author;
67+
}
68+
69+
/**
70+
* @param author
71+
* the author to set
72+
*/
73+
public void setAuthor(String author) {
74+
this.author = author;
75+
}
7376

77+
/*
78+
* (non-Javadoc)
79+
*
80+
* @see java.lang.Object#toString()
81+
*/
82+
@Override
83+
public String toString() {
84+
return "Book [id=" + id + ", name=" + name + ", author=" + author + "]";
85+
}
7486

7587
}

0 commit comments

Comments
 (0)