Jackson javadocs (#319)
* Jackson javadocs Signed-off-by: Francesco Guardiani <francescoguard@gmail.com> * Reverted public constructor and deprecated it Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
This commit is contained in:
parent
bd11010138
commit
00cdf9cb42
|
@ -37,7 +37,7 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* Jackson {@link com.fasterxml.jackson.databind.JsonDeserializer} for {@link CloudEvent}
|
* Jackson {@link com.fasterxml.jackson.databind.JsonDeserializer} for {@link CloudEvent}
|
||||||
*/
|
*/
|
||||||
public class CloudEventDeserializer extends StdDeserializer<CloudEvent> {
|
class CloudEventDeserializer extends StdDeserializer<CloudEvent> {
|
||||||
|
|
||||||
protected CloudEventDeserializer() {
|
protected CloudEventDeserializer() {
|
||||||
super(CloudEvent.class);
|
super(CloudEvent.class);
|
||||||
|
|
|
@ -33,7 +33,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
/**
|
/**
|
||||||
* Jackson {@link com.fasterxml.jackson.databind.JsonSerializer} for {@link CloudEvent}
|
* Jackson {@link com.fasterxml.jackson.databind.JsonSerializer} for {@link CloudEvent}
|
||||||
*/
|
*/
|
||||||
public class CloudEventSerializer extends StdSerializer<CloudEvent> {
|
class CloudEventSerializer extends StdSerializer<CloudEvent> {
|
||||||
|
|
||||||
private final boolean forceDataBase64Serialization;
|
private final boolean forceDataBase64Serialization;
|
||||||
private final boolean forceStringSerialization;
|
private final boolean forceStringSerialization;
|
||||||
|
|
|
@ -23,12 +23,16 @@ import io.cloudevents.CloudEventData;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a wrapper for Jackson {@link JsonNode} implementing the {@link CloudEventData}
|
* This class is a wrapper for Jackson {@link JsonNode} implementing {@link CloudEventData}.
|
||||||
*/
|
*/
|
||||||
public class JsonCloudEventData implements CloudEventData {
|
public class JsonCloudEventData implements CloudEventData {
|
||||||
|
|
||||||
private final JsonNode node;
|
private final JsonNode node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param node the json node to wrap
|
||||||
|
* @deprecated You should use {@link #wrap(JsonNode)}
|
||||||
|
*/
|
||||||
public JsonCloudEventData(JsonNode node) {
|
public JsonCloudEventData(JsonNode node) {
|
||||||
Objects.requireNonNull(node);
|
Objects.requireNonNull(node);
|
||||||
this.node = node;
|
this.node = node;
|
||||||
|
@ -39,6 +43,9 @@ public class JsonCloudEventData implements CloudEventData {
|
||||||
return node.toString().getBytes();
|
return node.toString().getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the wrapped {@link JsonNode}
|
||||||
|
*/
|
||||||
public JsonNode getNode() {
|
public JsonNode getNode() {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -62,4 +69,13 @@ public class JsonCloudEventData implements CloudEventData {
|
||||||
"node=" + node +
|
"node=" + node +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param node the json node to wrap
|
||||||
|
* @return json node wrapped in a {@link JsonCloudEventData}, which implements {@link CloudEventData}.
|
||||||
|
*/
|
||||||
|
public static JsonCloudEventData wrap(JsonNode node) {
|
||||||
|
return new JsonCloudEventData(node);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,29 @@ import java.io.IOException;
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link EventFormat} for <a href="https://github.com/cloudevents/spec/blob/v1.0/json-format.md">JSON event format</a>
|
* Implementation of {@link EventFormat} for <a href="https://github.com/cloudevents/spec/blob/v1.0/json-format.md">JSON event format</a>
|
||||||
* using Jackson. This format is resolvable with {@link io.cloudevents.core.provider.EventFormatProvider} using the content type {@link #CONTENT_TYPE}.
|
* using Jackson. This format is resolvable with {@link io.cloudevents.core.provider.EventFormatProvider} using the content type {@link #CONTENT_TYPE}.
|
||||||
|
* <p>
|
||||||
|
* If you want to use the {@link CloudEvent} serializers/deserializers directly in your mapper, you can use {@link #getCloudEventJacksonModule()} or
|
||||||
|
* {@link #getCloudEventJacksonModule(boolean, boolean)} to get a {@link SimpleModule} to register in your {@link ObjectMapper} instance.
|
||||||
*/
|
*/
|
||||||
public final class JsonFormat implements EventFormat {
|
public final class JsonFormat implements EventFormat {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content type associated with the JSON event format
|
||||||
|
*/
|
||||||
public static final String CONTENT_TYPE = "application/cloudevents+json";
|
public static final String CONTENT_TYPE = "application/cloudevents+json";
|
||||||
|
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
private final boolean forceDataBase64Serialization;
|
private final boolean forceDataBase64Serialization;
|
||||||
private final boolean forceStringSerialization;
|
private final boolean forceStringSerialization;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of this class customizing the serialization configuration.
|
||||||
|
*
|
||||||
|
* @param forceDataBase64Serialization force json base64 encoding for data
|
||||||
|
* @param forceStringSerialization force string serialization for non json data field
|
||||||
|
* @see #withForceJsonDataToBase64()
|
||||||
|
* @see #withForceNonJsonDataToString()
|
||||||
|
*/
|
||||||
public JsonFormat(boolean forceDataBase64Serialization, boolean forceStringSerialization) {
|
public JsonFormat(boolean forceDataBase64Serialization, boolean forceStringSerialization) {
|
||||||
this.mapper = new ObjectMapper();
|
this.mapper = new ObjectMapper();
|
||||||
this.mapper.registerModule(getCloudEventJacksonModule(forceDataBase64Serialization, forceStringSerialization));
|
this.mapper.registerModule(getCloudEventJacksonModule(forceDataBase64Serialization, forceStringSerialization));
|
||||||
|
@ -49,6 +63,9 @@ public final class JsonFormat implements EventFormat {
|
||||||
this.forceStringSerialization = forceStringSerialization;
|
this.forceStringSerialization = forceStringSerialization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of this class with default serialization configuration
|
||||||
|
*/
|
||||||
public JsonFormat() {
|
public JsonFormat() {
|
||||||
this(false, false);
|
this(false, false);
|
||||||
}
|
}
|
||||||
|
@ -106,15 +123,18 @@ public final class JsonFormat implements EventFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a JacksonModule with CloudEvent serializer/deserializer with default values
|
* @return a {@link SimpleModule} with {@link CloudEvent} serializer/deserializer configured using default values.
|
||||||
*/
|
*/
|
||||||
public static SimpleModule getCloudEventJacksonModule() {
|
public static SimpleModule getCloudEventJacksonModule() {
|
||||||
return getCloudEventJacksonModule(false, false);
|
return getCloudEventJacksonModule(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param forceDataBase64Serialization force json base64 encoding for data
|
||||||
|
* @param forceStringSerialization force string serialization for non json data field
|
||||||
* @return a JacksonModule with CloudEvent serializer/deserializer customizing the data serialization.
|
* @return a JacksonModule with CloudEvent serializer/deserializer customizing the data serialization.
|
||||||
* Look at {@link #withForceJsonDataToBase64()} and {@link #withForceNonJsonDataToString()} for more details.
|
* @see #withForceJsonDataToBase64()
|
||||||
|
* @see #withForceNonJsonDataToString()
|
||||||
*/
|
*/
|
||||||
public static SimpleModule getCloudEventJacksonModule(boolean forceDataBase64Serialization, boolean forceStringSerialization) {
|
public static SimpleModule getCloudEventJacksonModule(boolean forceDataBase64Serialization, boolean forceStringSerialization) {
|
||||||
final SimpleModule ceModule = new SimpleModule("CloudEvent");
|
final SimpleModule ceModule = new SimpleModule("CloudEvent");
|
||||||
|
@ -123,7 +143,7 @@ public final class JsonFormat implements EventFormat {
|
||||||
return ceModule;
|
return ceModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean dataIsJsonContentType(String contentType) {
|
static boolean dataIsJsonContentType(String contentType) {
|
||||||
// If content type, spec states that we should assume is json
|
// If content type, spec states that we should assume is json
|
||||||
return contentType == null || contentType.startsWith("application/json") || contentType.startsWith("text/json");
|
return contentType == null || contentType.startsWith("application/json") || contentType.startsWith("text/json");
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,11 @@ import io.cloudevents.rw.CloudEventRWException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class implements a {@link CloudEventDataMapper} that maps any input {@link CloudEventData} to the specified target type using the Jackson {@link ObjectMapper}.
|
||||||
|
*
|
||||||
|
* @param <T> the target type of the conversion
|
||||||
|
*/
|
||||||
public class PojoCloudEventDataMapper<T> implements CloudEventDataMapper<PojoCloudEventData<T>> {
|
public class PojoCloudEventDataMapper<T> implements CloudEventDataMapper<PojoCloudEventData<T>> {
|
||||||
|
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
|
|
1
pom.xml
1
pom.xml
|
@ -164,6 +164,7 @@
|
||||||
<link>https://jakarta.ee/specifications/platform/8/apidocs/</link>
|
<link>https://jakarta.ee/specifications/platform/8/apidocs/</link>
|
||||||
<link>https://kafka.apache.org/25/javadoc/</link>
|
<link>https://kafka.apache.org/25/javadoc/</link>
|
||||||
<link>https://qpid.apache.org/releases/qpid-proton-j-0.33.7/api/</link>
|
<link>https://qpid.apache.org/releases/qpid-proton-j-0.33.7/api/</link>
|
||||||
|
<link>https://fasterxml.github.io/jackson-databind/javadoc/2.10/</link>
|
||||||
</links>
|
</links>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
|
|
Loading…
Reference in New Issue