Skip to content

Commit 1b2aff6

Browse files
committed
serde serialization refactoring: collections API
1 parent 638baf4 commit 1b2aff6

24 files changed

+94
-39
lines changed

src/main/java/com/arangodb/internal/InternalArangoCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentCreateEntity<T>>>
180180
}
181181

182182
protected Request importDocumentsRequest(final String values, final DocumentImportOptions options) {
183-
return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(util().serialize(values));
183+
return importDocumentsRequest(options).putQueryParam("type", ImportType.auto).setBody(util().serialize(util().parseJson(values)));
184184
}
185185

186186
protected Request importDocumentsRequest(final Collection<?> values, final DocumentImportOptions options) {

src/main/java/com/arangodb/internal/util/DefaultArangoSerialization.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.arangodb.util.ArangoSerializer;
2929
import com.arangodb.velocypack.VPackParser;
3030
import com.arangodb.velocypack.VPackSlice;
31+
import com.fasterxml.jackson.databind.JsonNode;
3132

3233
import java.lang.reflect.Type;
3334

@@ -49,13 +50,12 @@ public DefaultArangoSerialization(final ArangoSerializer serializer, final Arang
4950

5051
@Override
5152
public VPackSlice serialize(final Object entity) throws ArangoDBException {
52-
// return serializer.serialize(entity);
5353
DataType dataType = serde.getDataType();
5454
switch (dataType) {
5555
case JSON:
5656
String json = new String(serde.serialize(entity));
5757
VPackParser parser = new VPackParser.Builder().build();
58-
return parser.fromJson(json);
58+
return parser.fromJson(json, true);
5959
case VPACK:
6060
return new VPackSlice(serde.serialize(entity));
6161
default:
@@ -73,4 +73,8 @@ public <T> T deserialize(final VPackSlice vpack, final Type type) throws ArangoD
7373
return deserializer.deserialize(vpack, type);
7474
}
7575

76+
@Override
77+
public JsonNode parseJson(String json) {
78+
return serde.parseJson(json);
79+
}
7680
}

src/main/java/com/arangodb/mapping/ArangoJack.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
*/
5252
public class ArangoJack implements ArangoSerialization {
5353

54+
@Override
55+
public JsonNode parseJson(String json) {
56+
return null;
57+
}
58+
5459
public interface ConfigureFunction {
5560
void configure(ObjectMapper mapper);
5661
}

src/main/java/com/arangodb/model/AqlFunctionCreateOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected AqlFunctionCreateOptions name(final String name) {
4444
return this;
4545
}
4646

47-
protected String getName() {
47+
public String getName() {
4848
return name;
4949
}
5050

@@ -57,7 +57,7 @@ protected AqlFunctionCreateOptions code(final String code) {
5757
return this;
5858
}
5959

60-
protected String getCode() {
60+
public String getCode() {
6161
return code;
6262
}
6363

src/main/java/com/arangodb/model/AqlQueryExplainOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected AqlQueryExplainOptions bindVars(final VPackSlice bindVars) {
5252
return this;
5353
}
5454

55-
protected String getQuery() {
55+
public String getQuery() {
5656
return query;
5757
}
5858

@@ -119,7 +119,7 @@ public static class Options {
119119
private Integer maxNumberOfPlans;
120120
private Boolean allPlans;
121121

122-
protected Optimizer getOptimizer() {
122+
public Optimizer getOptimizer() {
123123
if (optimizer == null) {
124124
optimizer = new Optimizer();
125125
}

src/main/java/com/arangodb/model/AqlQueryParseOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public AqlQueryParseOptions() {
3232
super();
3333
}
3434

35-
protected String getQuery() {
35+
public String getQuery() {
3636
return query;
3737
}
3838

src/main/java/com/arangodb/model/CollectionCreateOptions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import com.arangodb.entity.KeyType;
2626
import com.arangodb.entity.ReplicationFactor;
2727

28+
import java.util.Objects;
29+
2830
/**
2931
* @author Mark Vollmary
3032
* @see <a href="https://www.arangodb.com/docs/stable/http/collection-creating.html#create-collection">API
@@ -37,7 +39,7 @@ public class CollectionCreateOptions {
3739
private Integer writeConcern;
3840
private KeyOptions keyOptions;
3941
private Boolean waitForSync;
40-
private String[] shardKeys;
42+
private String[] shardKeys = new String[]{};
4143
private Integer numberOfShards;
4244
private Boolean isSystem;
4345
private CollectionType type;
@@ -166,6 +168,7 @@ public String[] getShardKeys() {
166168
* @return options
167169
*/
168170
public CollectionCreateOptions shardKeys(final String... shardKeys) {
171+
Objects.requireNonNull(shardKeys);
169172
this.shardKeys = shardKeys;
170173
return this;
171174
}

src/main/java/com/arangodb/model/CollectionSchema.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,25 @@
2222
package com.arangodb.model;
2323

2424

25+
import com.arangodb.serde.InternalSerializers;
26+
import com.fasterxml.jackson.annotation.JsonProperty;
27+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
28+
2529
/**
2630
* @author Michele Rastelli
2731
* @see <a href="https://www.arangodb.com/docs/stable/data-modeling-documents-schema-validation.html">API Documentation</a>
2832
* @since ArangoDB 3.7
2933
*/
3034
public class CollectionSchema {
3135

32-
/**
33-
* Value to unset the collection schema on properties update {@link com.arangodb.ArangoCollection#changeProperties(CollectionPropertiesOptions)}.
34-
*/
35-
public static final CollectionSchema NULL_SCHEMA = new CollectionSchema()
36-
.setLevel(null)
37-
.setMessage(null)
38-
.setRule(null);
39-
4036
private String rule;
4137
private Level level;
4238
private String message;
4339

4440
/**
4541
* @return JSON Schema description
4642
*/
43+
@JsonSerialize(using = InternalSerializers.CollectionSchemaRuleSerializer.class)
4744
public String getRule() {
4845
return rule;
4946
}
@@ -82,11 +79,13 @@ public enum Level {
8279
/**
8380
* The rule is inactive and validation thus turned off.
8481
*/
82+
@JsonProperty("none")
8583
NONE("none"),
8684

8785
/**
8886
* Only newly inserted documents are validated.
8987
*/
88+
@JsonProperty("new")
9089
NEW("new"),
9190

9291
/**
@@ -95,11 +94,13 @@ public enum Level {
9594
* but you want to stop the insertion of more invalid documents and prohibit that valid documents are changed to
9695
* invalid documents.
9796
*/
97+
@JsonProperty("moderate")
9898
MODERATE("moderate"),
9999

100100
/**
101101
* All new and modified document must strictly pass validation. No exceptions are made (default).
102102
*/
103+
@JsonProperty("strict")
103104
STRICT("strict");
104105

105106
private final String value;

src/main/java/com/arangodb/model/FulltextIndexOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected FulltextIndexOptions getThis() {
4242
return this;
4343
}
4444

45-
protected Iterable<String> getFields() {
45+
public Iterable<String> getFields() {
4646
return fields;
4747
}
4848

@@ -55,7 +55,7 @@ protected FulltextIndexOptions fields(final Iterable<String> fields) {
5555
return this;
5656
}
5757

58-
protected IndexType getType() {
58+
public IndexType getType() {
5959
return type;
6060
}
6161

src/main/java/com/arangodb/model/GeoIndexOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected GeoIndexOptions getThis() {
4141
return this;
4242
}
4343

44-
protected Iterable<String> getFields() {
44+
public Iterable<String> getFields() {
4545
return fields;
4646
}
4747

@@ -54,7 +54,7 @@ protected GeoIndexOptions fields(final Iterable<String> fields) {
5454
return this;
5555
}
5656

57-
protected IndexType getType() {
57+
public IndexType getType() {
5858
return type;
5959
}
6060

0 commit comments

Comments
 (0)