Skip to content

Commit d597252

Browse files
committed
Serializable field in Jackson
1 parent a1ff4c6 commit d597252

File tree

9 files changed

+409
-0
lines changed

9 files changed

+409
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.baeldung.jackson.field;
2+
3+
public class MyDto {
4+
5+
private String stringValue;
6+
private int intValue;
7+
private boolean booleanValue;
8+
9+
public MyDto() {
10+
super();
11+
}
12+
13+
public MyDto(final String stringValue, final int intValue, final boolean booleanValue) {
14+
super();
15+
16+
this.stringValue = stringValue;
17+
this.intValue = intValue;
18+
this.booleanValue = booleanValue;
19+
}
20+
21+
// API
22+
23+
public String getStringValue() {
24+
return stringValue;
25+
}
26+
27+
public void setStringValue(final String stringValue) {
28+
this.stringValue = stringValue;
29+
}
30+
31+
public int getIntValue() {
32+
return intValue;
33+
}
34+
35+
public void setIntValue(final int intValue) {
36+
this.intValue = intValue;
37+
}
38+
39+
public boolean getBooleanValue() {
40+
return booleanValue;
41+
}
42+
43+
public void setBooleanValue(final boolean booleanValue) {
44+
this.booleanValue = booleanValue;
45+
}
46+
47+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.baeldung.jackson.field;
2+
3+
public class MyDtoAccessLevel {
4+
5+
private String stringValue;
6+
int intValue;
7+
public boolean booleanValue;
8+
9+
public MyDtoAccessLevel() {
10+
super();
11+
}
12+
13+
public MyDtoAccessLevel(final String stringValue, final int intValue, final boolean booleanValue) {
14+
super();
15+
16+
this.stringValue = stringValue;
17+
this.intValue = intValue;
18+
this.booleanValue = booleanValue;
19+
}
20+
21+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.baeldung.jackson.field;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public class MyDtoCustomizedPropertyName {
6+
7+
private String stringValue;
8+
private int intValue;
9+
@JsonProperty("BOOLEANVALUE")
10+
private boolean booleanValue;
11+
12+
public MyDtoCustomizedPropertyName() {
13+
super();
14+
}
15+
16+
public MyDtoCustomizedPropertyName(final String stringValue, final int intValue, final boolean booleanValue) {
17+
super();
18+
19+
this.stringValue = stringValue;
20+
this.intValue = intValue;
21+
this.booleanValue = booleanValue;
22+
}
23+
24+
// API
25+
26+
public String getStringValue() {
27+
return stringValue;
28+
}
29+
30+
public void setStringValue(final String stringValue) {
31+
this.stringValue = stringValue;
32+
}
33+
34+
public int getIntValue() {
35+
return intValue;
36+
}
37+
38+
public void setIntValue(final int intValue) {
39+
this.intValue = intValue;
40+
}
41+
42+
public boolean getBooleanValue() {
43+
return booleanValue;
44+
}
45+
46+
public void setBooleanValue(final boolean booleanValue) {
47+
this.booleanValue = booleanValue;
48+
}
49+
50+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.baeldung.jackson.field;
2+
3+
public class MyDtoGetter {
4+
5+
private String stringValue;
6+
int intValue;
7+
public boolean booleanValue;
8+
9+
public MyDtoGetter() {
10+
super();
11+
}
12+
13+
public MyDtoGetter(final String stringValue, final int intValue, final boolean booleanValue) {
14+
super();
15+
16+
this.stringValue = stringValue;
17+
this.intValue = intValue;
18+
this.booleanValue = booleanValue;
19+
}
20+
21+
// API
22+
23+
public String getStringValue() {
24+
return stringValue;
25+
}
26+
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.baeldung.jackson.field;
2+
3+
public class MyDtoGetterImplicitDeserialization {
4+
5+
private String stringValue;
6+
int intValue;
7+
public boolean booleanValue;
8+
9+
public MyDtoGetterImplicitDeserialization() {
10+
super();
11+
}
12+
13+
public MyDtoGetterImplicitDeserialization(final String stringValue, final int intValue, final boolean booleanValue) {
14+
super();
15+
16+
this.stringValue = stringValue;
17+
this.intValue = intValue;
18+
this.booleanValue = booleanValue;
19+
}
20+
21+
// API
22+
23+
public String getStringValue() {
24+
return stringValue;
25+
}
26+
27+
public int getIntValue() {
28+
return intValue;
29+
}
30+
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.baeldung.jackson.field;
2+
3+
public class MyDtoSetter {
4+
5+
private String stringValue;
6+
int intValue;
7+
public boolean booleanValue;
8+
9+
public MyDtoSetter() {
10+
super();
11+
}
12+
13+
public MyDtoSetter(final String stringValue, final int intValue, final boolean booleanValue) {
14+
super();
15+
16+
this.stringValue = stringValue;
17+
this.intValue = intValue;
18+
this.booleanValue = booleanValue;
19+
}
20+
21+
// API
22+
23+
public String getStringValue() {
24+
return stringValue;
25+
}
26+
27+
public void setIntValue(final int intValue) {
28+
this.intValue = intValue;
29+
}
30+
31+
public int anotherGetIntValue() {
32+
return intValue;
33+
}
34+
35+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.baeldung.jackson.field;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
public class User {
7+
8+
private int id;
9+
private String name;
10+
@JsonIgnore
11+
private String password;
12+
13+
public User() {
14+
super();
15+
}
16+
17+
public User(final int id, final String name, final String password) {
18+
this.id = id;
19+
this.name = name;
20+
this.password = password;
21+
}
22+
23+
// API
24+
public int getId() {
25+
return id;
26+
}
27+
28+
public void setId(final int id) {
29+
this.id = id;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(final String name) {
37+
this.name = name;
38+
}
39+
40+
@JsonIgnore
41+
public String getPassword() {
42+
return password;
43+
}
44+
45+
@JsonProperty
46+
public void setPassword(final String password) {
47+
this.password = password;
48+
}
49+
50+
}

0 commit comments

Comments
 (0)