Skip to content

Commit 49dcdd5

Browse files
committed
JSON-B serde
1 parent 680e7fe commit 49dcdd5

File tree

17 files changed

+203
-90
lines changed

17 files changed

+203
-90
lines changed

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@
260260
<artifactId>jackson-dataformat-velocypack</artifactId>
261261
<optional>true</optional>
262262
</dependency>
263+
<dependency>
264+
<groupId>jakarta.json.bind</groupId>
265+
<artifactId>jakarta.json.bind-api</artifactId>
266+
<version>3.0.0</version>
267+
</dependency>
263268
<dependency>
264269
<groupId>ch.qos.logback</groupId>
265270
<artifactId>logback-classic</artifactId>
@@ -298,6 +303,12 @@
298303
<version>22.1.0</version>
299304
<scope>test</scope>
300305
</dependency>
306+
<dependency>
307+
<groupId>org.eclipse</groupId>
308+
<artifactId>yasson</artifactId>
309+
<version>3.0.0</version>
310+
<scope>test</scope>
311+
</dependency>
301312
</dependencies>
302313

303314
<dependencyManagement>

src/main/java/com/arangodb/entity/BaseDocument.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.arangodb.internal.DocumentFields;
2424
import com.fasterxml.jackson.annotation.JsonAnyGetter;
2525
import com.fasterxml.jackson.annotation.JsonAnySetter;
26+
import com.fasterxml.jackson.annotation.JsonInclude;
2627

2728
import java.io.Serializable;
2829
import java.util.HashMap;
@@ -94,6 +95,7 @@ public void setRevision(final String revision) {
9495
this.revision = revision;
9596
}
9697

98+
@JsonInclude
9799
@JsonAnyGetter
98100
public Map<String, Object> getProperties() {
99101
return properties;
@@ -103,6 +105,7 @@ public void setProperties(final Map<String, Object> properties) {
103105
this.properties = properties;
104106
}
105107

108+
@JsonInclude
106109
@JsonAnySetter
107110
public void addAttribute(final String key, final Object value) {
108111
properties.put(key, value);

src/main/java/com/arangodb/entity/From.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
55
import com.fasterxml.jackson.annotation.JsonInclude;
66
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import jakarta.json.bind.annotation.JsonbAnnotation;
8+
import jakarta.json.bind.annotation.JsonbProperty;
79

810
import java.lang.annotation.ElementType;
911
import java.lang.annotation.Retention;
@@ -19,5 +21,7 @@
1921
@JacksonAnnotationsInside
2022
@JsonProperty(DocumentFields.FROM)
2123
@JsonInclude(JsonInclude.Include.NON_NULL)
24+
@JsonbAnnotation
25+
@JsonbProperty("_from")
2226
public @interface From {
2327
}

src/main/java/com/arangodb/entity/Id.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
55
import com.fasterxml.jackson.annotation.JsonInclude;
66
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import jakarta.json.bind.annotation.JsonbAnnotation;
8+
import jakarta.json.bind.annotation.JsonbProperty;
79

810
import java.lang.annotation.ElementType;
911
import java.lang.annotation.Retention;
@@ -19,5 +21,7 @@
1921
@JacksonAnnotationsInside
2022
@JsonProperty(DocumentFields.ID)
2123
@JsonInclude(JsonInclude.Include.NON_NULL)
24+
@JsonbAnnotation
25+
@JsonbProperty("_id")
2226
public @interface Id {
2327
}

src/main/java/com/arangodb/entity/Key.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
55
import com.fasterxml.jackson.annotation.JsonInclude;
66
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import jakarta.json.bind.annotation.JsonbAnnotation;
8+
import jakarta.json.bind.annotation.JsonbProperty;
79

810
import java.lang.annotation.ElementType;
911
import java.lang.annotation.Retention;
@@ -19,5 +21,7 @@
1921
@JacksonAnnotationsInside
2022
@JsonProperty(DocumentFields.KEY)
2123
@JsonInclude(JsonInclude.Include.NON_NULL)
24+
@JsonbAnnotation
25+
@JsonbProperty("_key")
2226
public @interface Key {
2327
}

src/main/java/com/arangodb/entity/Rev.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
55
import com.fasterxml.jackson.annotation.JsonInclude;
66
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import jakarta.json.bind.annotation.JsonbAnnotation;
8+
import jakarta.json.bind.annotation.JsonbProperty;
79

810
import java.lang.annotation.ElementType;
911
import java.lang.annotation.Retention;
@@ -19,5 +21,7 @@
1921
@JacksonAnnotationsInside
2022
@JsonProperty(DocumentFields.REV)
2123
@JsonInclude(JsonInclude.Include.NON_NULL)
24+
@JsonbAnnotation
25+
@JsonbProperty("_rev")
2226
public @interface Rev {
2327
}

src/main/java/com/arangodb/entity/To.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
55
import com.fasterxml.jackson.annotation.JsonInclude;
66
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import jakarta.json.bind.annotation.JsonbAnnotation;
8+
import jakarta.json.bind.annotation.JsonbProperty;
79

810
import java.lang.annotation.ElementType;
911
import java.lang.annotation.Retention;
@@ -19,5 +21,7 @@
1921
@JacksonAnnotationsInside
2022
@JsonProperty(DocumentFields.TO)
2123
@JsonInclude(JsonInclude.Include.NON_NULL)
24+
@JsonbAnnotation
25+
@JsonbProperty("_to")
2226
public @interface To {
2327
}

src/main/java/com/arangodb/serde/ArangoSerde.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - low-level libraries without support to data binding
1414
* <p>
1515
* To create a custom serde based on Jackson, existing {@link JacksonSerde} can be reused and instantiated providing a
16-
* custom configured ObjectMapper ({@link JacksonSerde#of(com.fasterxml.jackson.databind.ObjectMapper)}) or configured
16+
* custom configured ObjectMapper ({@link JacksonSerde#create(com.fasterxml.jackson.databind.ObjectMapper)}) or configured
1717
* after creation through {@link JacksonSerde#configure(Consumer)}.
1818
*/
1919
public interface ArangoSerde {

src/main/java/com/arangodb/serde/InternalSerdeImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.arangodb.serde;
22

33
import com.arangodb.ArangoDBException;
4+
import com.arangodb.entity.BaseDocument;
45
import com.arangodb.util.RawBytes;
56
import com.arangodb.util.RawJson;
67
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -72,7 +73,11 @@ public JsonNode parse(byte[] content, String jsonPointer) {
7273
@Override
7374
public byte[] serializeUserData(Object value) {
7475
Class<?> clazz = value.getClass();
75-
if (RawJson.class.equals(clazz) || RawBytes.class.equals(clazz) || JsonNode.class.isAssignableFrom(clazz)) {
76+
if ( RawJson.class.equals(clazz) ||
77+
RawBytes.class.equals(clazz) ||
78+
JsonNode.class.isAssignableFrom(clazz) ||
79+
BaseDocument.class.isAssignableFrom(clazz)
80+
) {
7681
return serialize(value);
7782
} else {
7883
return userSerde.serialize(value);
@@ -90,7 +95,11 @@ public byte[] serializeCollectionUserData(Collection<?> value) {
9095

9196
@Override
9297
public <T> T deserializeUserData(byte[] content, Class<T> clazz) {
93-
if (RawJson.class.isAssignableFrom(clazz) || RawBytes.class.isAssignableFrom(clazz) || JsonNode.class.isAssignableFrom(clazz)) {
98+
if ( RawJson.class.isAssignableFrom(clazz) ||
99+
RawBytes.class.isAssignableFrom(clazz) ||
100+
JsonNode.class.isAssignableFrom(clazz) ||
101+
BaseDocument.class.isAssignableFrom(clazz)
102+
) {
94103
return deserialize(content, clazz);
95104
} else {
96105
return userSerde.deserialize(content, clazz);

src/main/java/com/arangodb/serde/JacksonSerde.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.function.Consumer;
66

77
/**
8-
* Contract for serialization/deserialization of user data, based on Jackson Databind.
8+
* User data serde based on Jackson Databind.
99
*/
1010
public interface JacksonSerde extends ArangoSerde {
1111

@@ -16,7 +16,7 @@ public interface JacksonSerde extends ArangoSerde {
1616
* @return the created JacksonSerde
1717
*/
1818
static JacksonSerde of(final DataType dataType) {
19-
return of(MapperProvider.of(dataType));
19+
return create(MapperProvider.of(dataType));
2020
}
2121

2222
/**
@@ -25,7 +25,7 @@ static JacksonSerde of(final DataType dataType) {
2525
* @param mapper Jackson ObjectMapper to use
2626
* @return the created JacksonSerde
2727
*/
28-
static JacksonSerde of(final ObjectMapper mapper) {
28+
static JacksonSerde create(final ObjectMapper mapper) {
2929
return new JacksonSerdeImpl(mapper);
3030
}
3131

0 commit comments

Comments
 (0)