Skip to content

Commit aa369fa

Browse files
author
eugenp
committed
Merge branch 'master' of https://github.com/eugenp/tutorials
2 parents 0fe9e10 + 5683fb5 commit aa369fa

14 files changed

+725
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
7+
public class BeanWithCreator {
8+
public int id;
9+
public String name;
10+
11+
@JsonCreator
12+
public BeanWithCreator(@JsonProperty("id") final int id, @JsonProperty("theName") final String name) {
13+
this.id = id;
14+
this.name = name;
15+
}
16+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import java.lang.annotation.Retention;
4+
import java.lang.annotation.RetentionPolicy;
5+
import java.util.Date;
6+
7+
import org.baeldung.jackson.annotation.BeanWithCustomAnnotation.CustomAnnotation;
8+
9+
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
10+
import com.fasterxml.jackson.annotation.JsonInclude;
11+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
12+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
13+
14+
@CustomAnnotation
15+
public class BeanWithCustomAnnotation {
16+
public int id;
17+
public String name;
18+
public Date dateCreated;
19+
20+
public BeanWithCustomAnnotation() {
21+
22+
}
23+
24+
public BeanWithCustomAnnotation(final int id, final String name, final Date dateCreated) {
25+
this.id = id;
26+
this.name = name;
27+
this.dateCreated = dateCreated;
28+
}
29+
30+
@Retention(RetentionPolicy.RUNTIME)
31+
@JacksonAnnotationsInside
32+
@JsonInclude(Include.NON_NULL)
33+
@JsonPropertyOrder({ "name", "id", "dateCreated" })
34+
public @interface CustomAnnotation {
35+
36+
}
37+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import com.fasterxml.jackson.annotation.JsonFilter;
4+
5+
@JsonFilter("myFilter")
6+
public class BeanWithFilter {
7+
public int id;
8+
public String name;
9+
10+
public BeanWithFilter() {
11+
12+
}
13+
14+
public BeanWithFilter(final int id, final String name) {
15+
this.id = id;
16+
this.name = name;
17+
}
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import com.fasterxml.jackson.annotation.JsonGetter;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.annotation.JsonSetter;
6+
7+
public class BeanWithGetter {
8+
public int id;
9+
private String name;
10+
11+
public BeanWithGetter() {
12+
13+
}
14+
15+
public BeanWithGetter(final int id, final String name) {
16+
this.id = id;
17+
this.name = name;
18+
}
19+
20+
@JsonProperty("name")
21+
@JsonSetter("name")
22+
public void setTheName(final String name) {
23+
this.name = name;
24+
}
25+
26+
@JsonProperty("name")
27+
@JsonGetter("name")
28+
public String getTheName() {
29+
return name;
30+
}
31+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
6+
@JsonIgnoreProperties({ "id" })
7+
public class BeanWithIgnore {
8+
@JsonIgnore
9+
public int id;
10+
public String name;
11+
12+
public BeanWithIgnore() {
13+
14+
}
15+
16+
public BeanWithIgnore(final int id, final String name) {
17+
this.id = id;
18+
this.name = name;
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import com.fasterxml.jackson.annotation.JacksonInject;
4+
5+
public class BeanWithInject {
6+
@JacksonInject
7+
public int id;
8+
public String name;
9+
10+
public BeanWithInject() {
11+
12+
}
13+
14+
public BeanWithInject(final int id, final String name) {
15+
this.id = id;
16+
this.name = name;
17+
}
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
7+
import com.fasterxml.jackson.annotation.JsonAnySetter;
8+
9+
public class ExtendableBean {
10+
public String name;
11+
private Map<String, String> properties;
12+
13+
public ExtendableBean() {
14+
properties = new HashMap<String, String>();
15+
}
16+
17+
public ExtendableBean(final String name) {
18+
this.name = name;
19+
properties = new HashMap<String, String>();
20+
}
21+
22+
@JsonAnySetter
23+
public void add(final String key, final String value) {
24+
properties.put(key, value);
25+
}
26+
27+
@JsonAnyGetter
28+
public Map<String, String> getProperties() {
29+
return properties;
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6+
7+
@JsonInclude(Include.NON_NULL)
8+
@JsonPropertyOrder({ "name", "id" })
9+
public class MyBean {
10+
public int id;
11+
public String name;
12+
13+
public MyBean() {
14+
15+
}
16+
17+
public MyBean(final int id, final String name) {
18+
this.id = id;
19+
this.name = name;
20+
}
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
4+
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
5+
6+
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
7+
public class PrivateBean {
8+
private int id;
9+
private String name;
10+
11+
public PrivateBean() {
12+
13+
}
14+
15+
public PrivateBean(final int id, final String name) {
16+
this.id = id;
17+
this.name = name;
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.baeldung.jackson.annotation;
2+
3+
import com.fasterxml.jackson.annotation.JsonRawValue;
4+
5+
public class RawBean {
6+
public String name;
7+
8+
@JsonRawValue
9+
public String json;
10+
11+
public RawBean() {
12+
13+
}
14+
15+
public RawBean(final String name, final String json) {
16+
this.name = name;
17+
this.json = json;
18+
}
19+
}

0 commit comments

Comments
 (0)