Skip to content

Commit 00cdf9c

Browse files
Jackson javadocs (#319)
* Jackson javadocs Signed-off-by: Francesco Guardiani <[email protected]> * Reverted public constructor and deprecated it Signed-off-by: Francesco Guardiani <[email protected]>
1 parent bd11010 commit 00cdf9c

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

formats/json-jackson/src/main/java/io/cloudevents/jackson/CloudEventDeserializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/**
3838
* Jackson {@link com.fasterxml.jackson.databind.JsonDeserializer} for {@link CloudEvent}
3939
*/
40-
public class CloudEventDeserializer extends StdDeserializer<CloudEvent> {
40+
class CloudEventDeserializer extends StdDeserializer<CloudEvent> {
4141

4242
protected CloudEventDeserializer() {
4343
super(CloudEvent.class);

formats/json-jackson/src/main/java/io/cloudevents/jackson/CloudEventSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/**
3434
* Jackson {@link com.fasterxml.jackson.databind.JsonSerializer} for {@link CloudEvent}
3535
*/
36-
public class CloudEventSerializer extends StdSerializer<CloudEvent> {
36+
class CloudEventSerializer extends StdSerializer<CloudEvent> {
3737

3838
private final boolean forceDataBase64Serialization;
3939
private final boolean forceStringSerialization;

formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonCloudEventData.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@
2323
import java.util.Objects;
2424

2525
/**
26-
* This class is a wrapper for Jackson {@link JsonNode} implementing the {@link CloudEventData}
26+
* This class is a wrapper for Jackson {@link JsonNode} implementing {@link CloudEventData}.
2727
*/
2828
public class JsonCloudEventData implements CloudEventData {
2929

3030
private final JsonNode node;
3131

32+
/**
33+
* @param node the json node to wrap
34+
* @deprecated You should use {@link #wrap(JsonNode)}
35+
*/
3236
public JsonCloudEventData(JsonNode node) {
3337
Objects.requireNonNull(node);
3438
this.node = node;
@@ -39,6 +43,9 @@ public byte[] toBytes() {
3943
return node.toString().getBytes();
4044
}
4145

46+
/**
47+
* @return the wrapped {@link JsonNode}
48+
*/
4249
public JsonNode getNode() {
4350
return node;
4451
}
@@ -62,4 +69,13 @@ public String toString() {
6269
"node=" + node +
6370
'}';
6471
}
72+
73+
/**
74+
* @param node the json node to wrap
75+
* @return json node wrapped in a {@link JsonCloudEventData}, which implements {@link CloudEventData}.
76+
*/
77+
public static JsonCloudEventData wrap(JsonNode node) {
78+
return new JsonCloudEventData(node);
79+
}
80+
6581
}

formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonFormat.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,39 @@
3333
/**
3434
* Implementation of {@link EventFormat} for <a href="https://github.com/cloudevents/spec/blob/v1.0/json-format.md">JSON event format</a>
3535
* using Jackson. This format is resolvable with {@link io.cloudevents.core.provider.EventFormatProvider} using the content type {@link #CONTENT_TYPE}.
36+
* <p>
37+
* If you want to use the {@link CloudEvent} serializers/deserializers directly in your mapper, you can use {@link #getCloudEventJacksonModule()} or
38+
* {@link #getCloudEventJacksonModule(boolean, boolean)} to get a {@link SimpleModule} to register in your {@link ObjectMapper} instance.
3639
*/
3740
public final class JsonFormat implements EventFormat {
3841

42+
/**
43+
* Content type associated with the JSON event format
44+
*/
3945
public static final String CONTENT_TYPE = "application/cloudevents+json";
4046

4147
private final ObjectMapper mapper;
4248
private final boolean forceDataBase64Serialization;
4349
private final boolean forceStringSerialization;
4450

51+
/**
52+
* Create a new instance of this class customizing the serialization configuration.
53+
*
54+
* @param forceDataBase64Serialization force json base64 encoding for data
55+
* @param forceStringSerialization force string serialization for non json data field
56+
* @see #withForceJsonDataToBase64()
57+
* @see #withForceNonJsonDataToString()
58+
*/
4559
public JsonFormat(boolean forceDataBase64Serialization, boolean forceStringSerialization) {
4660
this.mapper = new ObjectMapper();
4761
this.mapper.registerModule(getCloudEventJacksonModule(forceDataBase64Serialization, forceStringSerialization));
4862
this.forceDataBase64Serialization = forceDataBase64Serialization;
4963
this.forceStringSerialization = forceStringSerialization;
5064
}
5165

66+
/**
67+
* Create a new instance of this class with default serialization configuration
68+
*/
5269
public JsonFormat() {
5370
this(false, false);
5471
}
@@ -106,15 +123,18 @@ public String serializedContentType() {
106123
}
107124

108125
/**
109-
* @return a JacksonModule with CloudEvent serializer/deserializer with default values
126+
* @return a {@link SimpleModule} with {@link CloudEvent} serializer/deserializer configured using default values.
110127
*/
111128
public static SimpleModule getCloudEventJacksonModule() {
112129
return getCloudEventJacksonModule(false, false);
113130
}
114131

115132
/**
133+
* @param forceDataBase64Serialization force json base64 encoding for data
134+
* @param forceStringSerialization force string serialization for non json data field
116135
* @return a JacksonModule with CloudEvent serializer/deserializer customizing the data serialization.
117-
* Look at {@link #withForceJsonDataToBase64()} and {@link #withForceNonJsonDataToString()} for more details.
136+
* @see #withForceJsonDataToBase64()
137+
* @see #withForceNonJsonDataToString()
118138
*/
119139
public static SimpleModule getCloudEventJacksonModule(boolean forceDataBase64Serialization, boolean forceStringSerialization) {
120140
final SimpleModule ceModule = new SimpleModule("CloudEvent");
@@ -123,7 +143,7 @@ public static SimpleModule getCloudEventJacksonModule(boolean forceDataBase64Ser
123143
return ceModule;
124144
}
125145

126-
protected static boolean dataIsJsonContentType(String contentType) {
146+
static boolean dataIsJsonContentType(String contentType) {
127147
// If content type, spec states that we should assume is json
128148
return contentType == null || contentType.startsWith("application/json") || contentType.startsWith("text/json");
129149
}

formats/json-jackson/src/main/java/io/cloudevents/jackson/PojoCloudEventDataMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
import java.util.List;
1313

14+
/**
15+
* This class implements a {@link CloudEventDataMapper} that maps any input {@link CloudEventData} to the specified target type using the Jackson {@link ObjectMapper}.
16+
*
17+
* @param <T> the target type of the conversion
18+
*/
1419
public class PojoCloudEventDataMapper<T> implements CloudEventDataMapper<PojoCloudEventData<T>> {
1520

1621
private final ObjectMapper mapper;

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<link>https://jakarta.ee/specifications/platform/8/apidocs/</link>
165165
<link>https://kafka.apache.org/25/javadoc/</link>
166166
<link>https://qpid.apache.org/releases/qpid-proton-j-0.33.7/api/</link>
167+
<link>https://fasterxml.github.io/jackson-databind/javadoc/2.10/</link>
167168
</links>
168169
</configuration>
169170
<executions>

0 commit comments

Comments
 (0)