From 3144ffa138c6ef8f5eed2989ad1bb63b06910b17 Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Tue, 29 Sep 2020 18:16:22 +0100 Subject: [PATCH 01/13] Provide ability to override options used to serialize, use default option --- arangodb-net-standard.Test/Docs/UsageTest.cs | 2 +- .../JsonNetApiClientSerializationTest.cs | 10 ++--- arangodb-net-standard/ApiClientBase.cs | 7 +-- .../AqlFunctionApi/AqlFunctionApiClient.cs | 2 +- .../AuthApi/AuthApiClient.cs | 5 ++- .../CollectionApi/CollectionApiClient.cs | 14 +++--- .../CollectionApi/ICollectionApiClient.cs | 1 + .../CursorApi/CursorApiClient.cs | 13 ++++-- .../CursorApi/ICursorApiClient.cs | 8 +++- .../DatabaseApi/DatabaseApiClient.cs | 2 +- .../DocumentApi/DocumentApiClient.cs | 44 ++++++++++++------- .../DocumentApi/IDocumentApiClient.cs | 27 +++++++++--- .../GraphApi/GraphApiClient.cs | 40 ++++++++++------- .../GraphApi/IGraphApiClient.cs | 17 +++++-- .../Serialization/ApiClientSerialization.cs | 35 +++++++++++++++ .../ApiClientSerializationOptions.cs | 30 +++++++++++++ .../Serialization/IApiClientSerialization.cs | 10 +++-- .../IApiClientSerializationOptions.cs | 12 +++++ .../JsonNetApiClientSerialization.cs | 36 +++++++-------- .../TransactionApi/TransactionApiClient.cs | 2 +- .../UserApi/UserApiClient.cs | 10 ++--- 21 files changed, 233 insertions(+), 94 deletions(-) create mode 100644 arangodb-net-standard/Serialization/ApiClientSerialization.cs create mode 100644 arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs create mode 100644 arangodb-net-standard/Serialization/IApiClientSerializationOptions.cs diff --git a/arangodb-net-standard.Test/Docs/UsageTest.cs b/arangodb-net-standard.Test/Docs/UsageTest.cs index 0a5acc9b..c65cb09a 100644 --- a/arangodb-net-standard.Test/Docs/UsageTest.cs +++ b/arangodb-net-standard.Test/Docs/UsageTest.cs @@ -105,7 +105,7 @@ await adb.Document.PostDocumentAsync( // Run AQL query (create a query cursor) var response = await adb.Cursor.PostCursorAsync( @"FOR doc IN MyCollection - FILTER doc.ItemNumber == 123456 + FILTER doc.itemNumber == 123456 RETURN doc"); MyClassDocument item = response.Result.First(); diff --git a/arangodb-net-standard.Test/Serialization/JsonNetApiClientSerializationTest.cs b/arangodb-net-standard.Test/Serialization/JsonNetApiClientSerializationTest.cs index f5f10ed6..5de7626a 100644 --- a/arangodb-net-standard.Test/Serialization/JsonNetApiClientSerializationTest.cs +++ b/arangodb-net-standard.Test/Serialization/JsonNetApiClientSerializationTest.cs @@ -22,7 +22,7 @@ public void Serialize_ShouldSucceed() var serialization = new JsonNetApiClientSerialization(); - byte[] jsonBytes = serialization.Serialize(model, true, true); + byte[] jsonBytes = serialization.Serialize(model, new ApiClientSerializationOptions(true, true)); string jsonString = Encoding.UTF8.GetString(jsonBytes); @@ -42,7 +42,7 @@ public void Serialize_ShouldNotCamelCaseBindVars_WhenSerializingPostCursorBody() }; var serialization = new JsonNetApiClientSerialization(); - byte[] jsonBytes = serialization.Serialize(body, true, true); + byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(true, true)); string jsonString = Encoding.UTF8.GetString(jsonBytes); @@ -65,7 +65,7 @@ public void Serialize_ShouldNotCamelCaseParams_WhenSerializingPostTransactionBod var serialization = new JsonNetApiClientSerialization(); - byte[] jsonBytes = serialization.Serialize(body, true, true); + byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(true, true)); string jsonString = Encoding.UTF8.GetString(jsonBytes); @@ -88,7 +88,7 @@ public void Serialize_ShouldNotIgnoreNull_WhenSerializingPostCursorBody() }; var serialization = new JsonNetApiClientSerialization(); - byte[] jsonBytes = serialization.Serialize(body, true, true); + byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(true, true)); string jsonString = Encoding.UTF8.GetString(jsonBytes); @@ -109,7 +109,7 @@ public void Serialize_ShouldNotIgnoreNull_WhenSerializingPostTransactionBody() var serialization = new JsonNetApiClientSerialization(); - byte[] jsonBytes = serialization.Serialize(body, true, true); + byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(true, true)); string jsonString = Encoding.UTF8.GetString(jsonBytes); diff --git a/arangodb-net-standard/ApiClientBase.cs b/arangodb-net-standard/ApiClientBase.cs index 04931830..c718c4ae 100644 --- a/arangodb-net-standard/ApiClientBase.cs +++ b/arangodb-net-standard/ApiClientBase.cs @@ -66,14 +66,11 @@ protected T DeserializeJsonFromStream(Stream stream) } } - protected byte[] GetContent(T item, bool useCamelCasePropertyNames, bool ignoreNullValues) + protected byte[] GetContent(T item, IApiClientSerializationOptions options) { try { - return _serialization.Serialize( - item, - useCamelCasePropertyNames, - ignoreNullValues); + return _serialization.Serialize(item, options); } catch (Exception e) { diff --git a/arangodb-net-standard/AqlFunctionApi/AqlFunctionApiClient.cs b/arangodb-net-standard/AqlFunctionApi/AqlFunctionApiClient.cs index 697423ef..38c250ee 100644 --- a/arangodb-net-standard/AqlFunctionApi/AqlFunctionApiClient.cs +++ b/arangodb-net-standard/AqlFunctionApi/AqlFunctionApiClient.cs @@ -53,7 +53,7 @@ public AqlFunctionApiClient(IApiClientTransport transport, IApiClientSerializati /// public virtual async Task PostAqlFunctionAsync(PostAqlFunctionBody body) { - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PostAsync(_apiPath, content)) { diff --git a/arangodb-net-standard/AuthApi/AuthApiClient.cs b/arangodb-net-standard/AuthApi/AuthApiClient.cs index 32e0e2b3..a57d65ee 100644 --- a/arangodb-net-standard/AuthApi/AuthApiClient.cs +++ b/arangodb-net-standard/AuthApi/AuthApiClient.cs @@ -58,9 +58,10 @@ public virtual async Task GetJwtTokenAsync(string username, st /// /// Object containing username and password. /// Object containing the encoded JWT token value. - public virtual async Task GetJwtTokenAsync(JwtTokenRequestBody body) + public virtual async Task GetJwtTokenAsync( + JwtTokenRequestBody body) { - byte[] content = GetContent(body, true, false); + byte[] content = GetContent(body, new ApiClientSerializationOptions(true, false)); using (var response = await _client.PostAsync("/_open/auth", content)) { if (response.IsSuccessStatusCode) diff --git a/arangodb-net-standard/CollectionApi/CollectionApiClient.cs b/arangodb-net-standard/CollectionApi/CollectionApiClient.cs index fd57bde0..33fce5d0 100644 --- a/arangodb-net-standard/CollectionApi/CollectionApiClient.cs +++ b/arangodb-net-standard/CollectionApi/CollectionApiClient.cs @@ -45,14 +45,16 @@ public CollectionApiClient(IApiClientTransport transport, IApiClientSerializatio _transport = transport; } - public virtual async Task PostCollectionAsync(PostCollectionBody body, PostCollectionQuery options = null) + public virtual async Task PostCollectionAsync( + PostCollectionBody body, + PostCollectionQuery options = null) { string uriString = _collectionApiPath; if (options != null) { uriString += "?" + options.ToQueryString(); } - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PostAsync(uriString, content)) { var stream = await response.Content.ReadAsStreamAsync(); @@ -189,7 +191,7 @@ public virtual async Task GetCollectionProperti /// public virtual async Task RenameCollectionAsync(string collectionName, RenameCollectionBody body) { - var content = GetContent(body, true, false); + var content = GetContent(body, new ApiClientSerializationOptions(true, false)); using (var response = await _transport.PutAsync(_collectionApiPath + "/" + WebUtility.UrlEncode(collectionName) + "/rename", content)) { if (response.IsSuccessStatusCode) @@ -228,9 +230,11 @@ public virtual async Task GetCollectionRevisionAs /// /// /// - public virtual async Task PutCollectionPropertyAsync(string collectionName, PutCollectionPropertyBody body) + public virtual async Task PutCollectionPropertyAsync( + string collectionName, + PutCollectionPropertyBody body) { - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PutAsync(_collectionApiPath + "/" + collectionName + "/properties", content)) { if (response.IsSuccessStatusCode) diff --git a/arangodb-net-standard/CollectionApi/ICollectionApiClient.cs b/arangodb-net-standard/CollectionApi/ICollectionApiClient.cs index d0991bfd..1959b360 100644 --- a/arangodb-net-standard/CollectionApi/ICollectionApiClient.cs +++ b/arangodb-net-standard/CollectionApi/ICollectionApiClient.cs @@ -1,4 +1,5 @@ using ArangoDBNetStandard.CollectionApi.Models; +using ArangoDBNetStandard.Serialization; using System.Threading.Tasks; namespace ArangoDBNetStandard.CollectionApi diff --git a/arangodb-net-standard/CursorApi/CursorApiClient.cs b/arangodb-net-standard/CursorApi/CursorApiClient.cs index a345a5b0..cddcf38d 100644 --- a/arangodb-net-standard/CursorApi/CursorApiClient.cs +++ b/arangodb-net-standard/CursorApi/CursorApiClient.cs @@ -57,6 +57,7 @@ public CursorApiClient(IApiClientTransport client, IApiClientSerialization seria /// /// /// + /// /// public virtual async Task> PostCursorAsync( string query, @@ -66,7 +67,8 @@ public virtual async Task> PostCursorAsync( long? batchSize = null, bool? cache = null, long? memoryLimit = null, - int? ttl = null) + int? ttl = null, + IApiClientSerializationOptions serializationOptions = null) { return await PostCursorAsync(new PostCursorBody { @@ -78,17 +80,20 @@ public virtual async Task> PostCursorAsync( Cache = cache, MemoryLimit = memoryLimit, Ttl = ttl - }); + }, serializationOptions); } /// /// Execute an AQL query, creating a cursor which can be used to page query results. /// /// Object encapsulating options and parameters of the query. + /// /// - public virtual async Task> PostCursorAsync(PostCursorBody postCursorBody) + public virtual async Task> PostCursorAsync( + PostCursorBody postCursorBody, + IApiClientSerializationOptions serializationOptions = null) { - var content = GetContent(postCursorBody, true, true); + var content = GetContent(postCursorBody, serializationOptions); using (var response = await _client.PostAsync(_cursorApiPath, content)) { if (response.IsSuccessStatusCode) diff --git a/arangodb-net-standard/CursorApi/ICursorApiClient.cs b/arangodb-net-standard/CursorApi/ICursorApiClient.cs index 5e6da707..b5f7a651 100644 --- a/arangodb-net-standard/CursorApi/ICursorApiClient.cs +++ b/arangodb-net-standard/CursorApi/ICursorApiClient.cs @@ -1,4 +1,5 @@ using ArangoDBNetStandard.CursorApi.Models; +using ArangoDBNetStandard.Serialization; using System.Collections.Generic; using System.Threading.Tasks; @@ -30,14 +31,17 @@ Task> PostCursorAsync( long? batchSize = null, bool? cache = null, long? memoryLimit = null, - int? ttl = null); + int? ttl = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Execute an AQL query, creating a cursor which can be used to page query results. /// /// Object encapsulating options and parameters of the query. /// - Task> PostCursorAsync(PostCursorBody postCursorBody); + Task> PostCursorAsync( + PostCursorBody postCursorBody, + IApiClientSerializationOptions serializationOptions = null); /// /// Deletes an existing cursor and frees the resources associated with it. diff --git a/arangodb-net-standard/DatabaseApi/DatabaseApiClient.cs b/arangodb-net-standard/DatabaseApi/DatabaseApiClient.cs index 3484c997..a9b75f59 100644 --- a/arangodb-net-standard/DatabaseApi/DatabaseApiClient.cs +++ b/arangodb-net-standard/DatabaseApi/DatabaseApiClient.cs @@ -53,7 +53,7 @@ public DatabaseApiClient(IApiClientTransport client, IApiClientSerialization ser /// public virtual async Task PostDatabaseAsync(PostDatabaseBody request) { - var content = GetContent(request, true, true); + var content = GetContent(request, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PostAsync(_databaseApiPath, content)) { if (response.IsSuccessStatusCode) diff --git a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs index 06842e86..c2264425 100644 --- a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs @@ -52,18 +52,20 @@ public DocumentApiClient(IApiClientTransport client, IApiClientSerialization ser /// /// /// + /// /// public virtual async Task> PostDocumentAsync( string collectionName, T document, - PostDocumentsQuery query = null) + PostDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { string uriString = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uriString += "?" + query.ToQueryString(); } - var content = GetContent(document, false, false); + var content = GetContent(document, serializationOptions); using (var response = await _client.PostAsync(uriString, content)) { if (response.IsSuccessStatusCode) @@ -82,18 +84,20 @@ public virtual async Task> PostDocumentAsync( /// /// /// + /// /// public virtual async Task> PostDocumentsAsync( string collectionName, IList documents, - PostDocumentsQuery query = null) + PostDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { string uriString = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uriString += "?" + query.ToQueryString(); } - var content = GetContent(documents, false, false); + var content = GetContent(documents, serializationOptions); using (var response = await _client.PostAsync(uriString, content)) { if (response.IsSuccessStatusCode) @@ -119,18 +123,20 @@ public virtual async Task> PostDocumentsAsync( /// /// /// + /// /// public virtual async Task> PutDocumentsAsync( string collectionName, IList documents, - PutDocumentsQuery query = null) + PutDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } - var content = GetContent(documents, false, false); + var content = GetContent(documents, serializationOptions); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -158,11 +164,13 @@ public virtual async Task> PutDocumentsAsync( /// /// /// + /// /// public virtual async Task> PutDocumentAsync( string documentId, T doc, - PutDocumentQuery opts = null) + PutDocumentQuery opts = null, + IApiClientSerializationOptions serializationOptions = null) { ValidateDocumentId(documentId); string uri = _docApiPath + "/" + documentId; @@ -170,7 +178,7 @@ public virtual async Task> PutDocumentAsync( { uri += "?" + opts.ToQueryString(); } - var content = GetContent(doc, false, false); + var content = GetContent(doc, serializationOptions); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -251,7 +259,7 @@ public virtual async Task> GetDocumentsAsync( { string uri = $"{_docApiPath}/{WebUtility.UrlEncode(collectionName)}?onlyget=true"; - var content = GetContent(selectors, false, true); + var content = GetContent(selectors, new ApiClientSerializationOptions(false, true)); using (var response = await _client.PutAsync(uri, content)) { @@ -383,18 +391,20 @@ public virtual async Task> DeleteDocumentsAsync( /// /// /// + /// /// public virtual async Task> DeleteDocumentsAsync( string collectionName, IList selectors, - DeleteDocumentsQuery query = null) + DeleteDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } - var content = GetContent(selectors, false, false); + var content = GetContent(selectors, serializationOptions); using (var response = await _client.DeleteAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -434,18 +444,20 @@ public virtual async Task> DeleteDocumentsAsync( /// /// /// + /// /// public virtual async Task> PatchDocumentsAsync( string collectionName, IList patches, - PatchDocumentsQuery query = null) + PatchDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } - var content = GetContent(patches, false, false); + var content = GetContent(patches, serializationOptions); using (var response = await _client.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -510,11 +522,13 @@ public virtual async Task> PatchDocumentAsync( /// /// /// + /// /// public virtual async Task> PatchDocumentAsync( string documentId, T body, - PatchDocumentQuery query = null) + PatchDocumentQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { ValidateDocumentId(documentId); string uriString = _docApiPath + "/" + documentId; @@ -522,7 +536,7 @@ public virtual async Task> PatchDocumentAsync( { uriString += "?" + query.ToQueryString(); } - var content = GetContent(body, false, false); + var content = GetContent(body, serializationOptions); using (var response = await _client.PatchAsync(uriString, content)) { if (response.IsSuccessStatusCode) diff --git a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs index b790cac0..0961342e 100644 --- a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs @@ -1,4 +1,5 @@ using ArangoDBNetStandard.DocumentApi.Models; +using ArangoDBNetStandard.Serialization; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -17,11 +18,13 @@ public interface IDocumentApiClient /// /// /// + /// /// Task> PostDocumentAsync( string collectionName, T document, - PostDocumentsQuery query = null); + PostDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Post multiple documents in a single request. @@ -30,11 +33,13 @@ Task> PostDocumentAsync( /// /// /// + /// /// Task> PostDocumentsAsync( string collectionName, IList documents, - PostDocumentsQuery query = null); + PostDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Replace multiple documents. @@ -43,11 +48,13 @@ Task> PostDocumentsAsync( /// /// /// + /// /// Task> PutDocumentsAsync( string collectionName, IList documents, - PutDocumentsQuery query = null); + PutDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Replaces the document with the provided document ID with the one in @@ -58,11 +65,13 @@ Task> PutDocumentsAsync( /// /// /// + /// /// Task> PutDocumentAsync( string documentId, T doc, - PutDocumentQuery opts = null); + PutDocumentQuery opts = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Replaces the document based on its Document ID with the one in @@ -180,6 +189,7 @@ Task> DeleteDocumentAsync( /// /// /// + /// /// Task> DeleteDocumentsAsync( string collectionName, @@ -198,7 +208,8 @@ Task> DeleteDocumentsAsync( Task> DeleteDocumentsAsync( string collectionName, IList selectors, - DeleteDocumentsQuery query = null); + DeleteDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Partially updates documents, the documents to update are specified @@ -227,7 +238,8 @@ Task> DeleteDocumentsAsync( Task> PatchDocumentsAsync( string collectionName, IList patches, - PatchDocumentsQuery query = null); + PatchDocumentsQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Partially updates the document identified by document-handle. @@ -273,7 +285,8 @@ Task> PatchDocumentAsync( Task> PatchDocumentAsync( string documentId, T body, - PatchDocumentQuery query = null); + PatchDocumentQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Like GET, but only returns the header fields and not the body. You diff --git a/arangodb-net-standard/GraphApi/GraphApiClient.cs b/arangodb-net-standard/GraphApi/GraphApiClient.cs index 200d6897..cc622b7c 100644 --- a/arangodb-net-standard/GraphApi/GraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/GraphApiClient.cs @@ -2,6 +2,7 @@ using ArangoDBNetStandard.Serialization; using ArangoDBNetStandard.Transport; using System; +using System.Collections; using System.Net; using System.Threading.Tasks; @@ -64,7 +65,7 @@ public virtual async Task PostGraphAsync( uri += "?" + query.ToQueryString(); } - var content = GetContent(postGraphBody, true, true); + var content = GetContent(postGraphBody, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PostAsync(uri, content)) { @@ -203,7 +204,7 @@ public virtual async Task PostEdgeDefinitionAsync( string graphName, PostEdgeDefinitionBody body) { - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); string uri = _graphApiPath + "/" + WebUtility.UrlEncode(graphName) + "/edge"; @@ -232,7 +233,7 @@ public virtual async Task PostVertexCollectionAsyn { string uri = _graphApiPath + '/' + WebUtility.UrlEncode(graphName) + "/vertex"; - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PostAsync(uri, content)) { @@ -254,12 +255,14 @@ public virtual async Task PostVertexCollectionAsyn /// /// /// + /// /// public virtual async Task> PostVertexAsync( string graphName, string collectionName, T vertex, - PostVertexQuery query = null) + PostVertexQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { string uri = _graphApiPath + '/' + WebUtility.UrlEncode(graphName) + "/vertex/" + WebUtility.UrlEncode(collectionName); @@ -267,7 +270,7 @@ public virtual async Task> PostVertexAsync( { uri += "?" + query.ToQueryString(); } - var content = GetContent(vertex, false, false); + var content = GetContent(vertex, serializationOptions); using (var response = await _transport.PostAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -358,14 +361,16 @@ public virtual async Task DeleteVertexCollection /// The name of the edge collection the edge belongs to. /// The edge to create. /// Optional query parameters of the request. + /// /// public virtual async Task> PostEdgeAsync( string graphName, string collectionName, T edge, - PostEdgeQuery query = null) + PostEdgeQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { - var content = GetContent(edge, false, false); + var content = GetContent(edge, serializationOptions); string uri = _graphApiPath + "/" + WebUtility.UrlEncode(graphName) + "/edge/" + WebUtility.UrlEncode(collectionName); @@ -621,19 +626,22 @@ public virtual async Task> DeleteVertexAsync( /// /// /// + /// /// public virtual Task> PatchVertexAsync( string graphName, string collectionName, string vertexKey, T body, - PatchVertexQuery query = null) + PatchVertexQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { return PatchVertexAsync( graphName, WebUtility.UrlEncode(collectionName) + "/" + WebUtility.UrlEncode(vertexKey), body, - query); + query, + serializationOptions); } /// @@ -648,12 +656,14 @@ public virtual Task> PatchVertexAsync( /// The document ID of the vertex to update. /// /// + /// /// public virtual async Task> PatchVertexAsync( string graphName, string documentId, T body, - PatchVertexQuery query = null) + PatchVertexQuery query = null, + IApiClientSerializationOptions serializationOptions = null) { ValidateDocumentId(documentId); @@ -665,7 +675,7 @@ public virtual async Task> PatchVertexAsync( uri += "?" + query.ToQueryString(); } - var content = GetContent(body, false, false); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -728,7 +738,7 @@ public virtual async Task> PutEdgeAsync( uri += "?" + query.ToQueryString(); } - var content = GetContent(edge, false, false); + var content = GetContent(edge, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -764,7 +774,7 @@ public virtual async Task PutEdgeDefinitionAsync( { uriString += "?" + query.ToQueryString(); } - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PutAsync(uriString, content)) { if (response.IsSuccessStatusCode) @@ -830,7 +840,7 @@ public virtual async Task> PatchEdgeAsync( uri += "?" + query.ToQueryString(); } - var content = GetContent(edge, true, true); + var content = GetContent(edge, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -892,7 +902,7 @@ public virtual async Task> PutVertexAsync( uri += "?" + query.ToQueryString(); } - var content = GetContent(vertex, true, true); + var content = GetContent(vertex, new ApiClientSerializationOptions(true, true)); using (var response = await _transport.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) diff --git a/arangodb-net-standard/GraphApi/IGraphApiClient.cs b/arangodb-net-standard/GraphApi/IGraphApiClient.cs index 6242b085..495160a4 100644 --- a/arangodb-net-standard/GraphApi/IGraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/IGraphApiClient.cs @@ -1,4 +1,5 @@ using ArangoDBNetStandard.GraphApi.Models; +using ArangoDBNetStandard.Serialization; using System.Threading.Tasks; namespace ArangoDBNetStandard.GraphApi @@ -106,12 +107,14 @@ Task PostVertexCollectionAsync( /// /// /// + /// /// Task> PostVertexAsync( string graphName, string collectionName, T vertex, - PostVertexQuery query = null); + PostVertexQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Remove one edge definition from the graph. This will only remove the @@ -158,12 +161,14 @@ Task DeleteVertexCollectionAsync( /// The name of the edge collection the edge belongs to. /// The edge to create. /// + /// /// Task> PostEdgeAsync( string graphName, string collectionName, T edge, - PostEdgeQuery query = null); + PostEdgeQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Gets an edge from the given graph using the edge collection and _key attribute. @@ -292,13 +297,15 @@ Task> DeleteVertexAsync( /// /// /// + /// /// Task> PatchVertexAsync( string graphName, string collectionName, string vertexKey, T body, - PatchVertexQuery query = null); + PatchVertexQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Updates the data of the specific vertex based on its document ID. @@ -311,12 +318,14 @@ Task> PatchVertexAsync( /// The document ID of the vertex to update. /// /// + /// /// Task> PatchVertexAsync( string graphName, string documentId, T body, - PatchVertexQuery query = null); + PatchVertexQuery query = null, + IApiClientSerializationOptions serializationOptions = null); /// /// Replaces the data of an edge in the collection. diff --git a/arangodb-net-standard/Serialization/ApiClientSerialization.cs b/arangodb-net-standard/Serialization/ApiClientSerialization.cs new file mode 100644 index 00000000..25840a1f --- /dev/null +++ b/arangodb-net-standard/Serialization/ApiClientSerialization.cs @@ -0,0 +1,35 @@ +using System.IO; + +namespace ArangoDBNetStandard.Serialization +{ + /// + /// The Api client serilization abastract class. + /// Used as a base to implement custom serilizations. + /// + public abstract class ApiClientSerialization : IApiClientSerialization + { + /// + /// The default serialization options. + /// + public abstract IApiClientSerializationOptions DefaultOptions { get; } + + /// + /// Deserializes the data structure contained by the specified stream + /// into an instance of the specified type. + /// + /// The type of the object to deserialize to. + /// The stream containing the JSON structure to deserialize. + /// + public abstract T DeserializeFromStream(Stream stream); + + /// + /// Serializes the specified object to a sequence of bytes, + /// following the provided rules for camel case property name and null value handling. + /// + /// The type of the object to serialize. + /// The object to serialize. + /// The serialization content type. + /// + public abstract byte[] Serialize(T item, IApiClientSerializationOptions options); + } +} diff --git a/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs b/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs new file mode 100644 index 00000000..06b56507 --- /dev/null +++ b/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs @@ -0,0 +1,30 @@ +namespace ArangoDBNetStandard.Serialization +{ + /// + /// The API client serilization options class. + /// + public class ApiClientSerializationOptions : IApiClientSerializationOptions + { + /// + /// Use camlel case if true, otherwise depends on + /// the action will be implemented in the serializer. + /// + public bool UseCamelCasePropertyNames { get; } + + /// + /// True to ignore values, otherwise false. + /// + public bool IgnoreNullValues { get; } + + /// + /// + /// + /// + /// + public ApiClientSerializationOptions(bool useCamelCasePropertyNames, bool ignoreNullValues) + { + UseCamelCasePropertyNames = useCamelCasePropertyNames; + IgnoreNullValues = ignoreNullValues; + } + } +} diff --git a/arangodb-net-standard/Serialization/IApiClientSerialization.cs b/arangodb-net-standard/Serialization/IApiClientSerialization.cs index abfa7a6c..06968d4b 100644 --- a/arangodb-net-standard/Serialization/IApiClientSerialization.cs +++ b/arangodb-net-standard/Serialization/IApiClientSerialization.cs @@ -7,6 +7,11 @@ namespace ArangoDBNetStandard.Serialization /// public interface IApiClientSerialization { + /// + /// The default serialization options. + /// + IApiClientSerializationOptions DefaultOptions { get; } + /// /// Deserializes the data structure contained by the specified stream /// into an instance of the specified type. @@ -22,9 +27,8 @@ public interface IApiClientSerialization /// /// The type of the object to serialize. /// The object to serialize. - /// Whether property names should be camel cased. - /// Whether null values should be ignored. + /// The serialization content type. /// - byte[] Serialize(T item, bool useCamelCasePropertyNames, bool ignoreNullValues); + byte[] Serialize(T item, IApiClientSerializationOptions options); } } diff --git a/arangodb-net-standard/Serialization/IApiClientSerializationOptions.cs b/arangodb-net-standard/Serialization/IApiClientSerializationOptions.cs new file mode 100644 index 00000000..d61af746 --- /dev/null +++ b/arangodb-net-standard/Serialization/IApiClientSerializationOptions.cs @@ -0,0 +1,12 @@ +namespace ArangoDBNetStandard.Serialization +{ + /// + /// Define the options. + /// + public interface IApiClientSerializationOptions + { + bool IgnoreNullValues { get; } + + bool UseCamelCasePropertyNames { get; } + } +} diff --git a/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs b/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs index a7f9a182..5f3858f2 100644 --- a/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs +++ b/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs @@ -1,9 +1,5 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using System; -using System.Collections.Generic; using System.IO; -using System.Reflection; using System.Text; namespace ArangoDBNetStandard.Serialization @@ -11,8 +7,10 @@ namespace ArangoDBNetStandard.Serialization /// /// Implements a that uses Json.NET. /// - public class JsonNetApiClientSerialization : IApiClientSerialization + public class JsonNetApiClientSerialization : ApiClientSerialization { + public override IApiClientSerializationOptions DefaultOptions => new ApiClientSerializationOptions(true, true); + /// /// Deserializes the JSON structure contained by the specified stream /// into an instance of the specified type. @@ -20,7 +18,7 @@ public class JsonNetApiClientSerialization : IApiClientSerialization /// The type of the object to deserialize to. /// The stream containing the JSON structure to deserialize. /// - public virtual T DeserializeFromStream(Stream stream) + public override T DeserializeFromStream(Stream stream) { if (stream == null || stream.CanRead == false) { @@ -39,25 +37,27 @@ public virtual T DeserializeFromStream(Stream stream) } /// - /// Serializes the specified object to a JSON string encoded as UTF-8 bytes, - /// following the provided rules for camel case property name and null value handling. + /// /// - /// The type of the object to serialize. - /// The object to serialize. - /// Whether property names should be camel cased (camelCase). - /// Whether null values should be ignored. + /// + /// + /// /// - public virtual byte[] Serialize( - T item, - bool useCamelCasePropertyNames, - bool ignoreNullValues) + + public override byte[] Serialize(T item, IApiClientSerializationOptions options) { + // When no options passed use the default. + if(options == null) + { + options = DefaultOptions; + } + var jsonSettings = new JsonSerializerSettings { - NullValueHandling = ignoreNullValues ? NullValueHandling.Ignore : NullValueHandling.Include + NullValueHandling = options.IgnoreNullValues ? NullValueHandling.Ignore : NullValueHandling.Include }; - if (useCamelCasePropertyNames) + if (options.UseCamelCasePropertyNames) { jsonSettings.ContractResolver = new CamelCasePropertyNamesExceptDictionaryContractResolver(); } diff --git a/arangodb-net-standard/TransactionApi/TransactionApiClient.cs b/arangodb-net-standard/TransactionApi/TransactionApiClient.cs index 70d22940..0cad1514 100644 --- a/arangodb-net-standard/TransactionApi/TransactionApiClient.cs +++ b/arangodb-net-standard/TransactionApi/TransactionApiClient.cs @@ -52,7 +52,7 @@ public TransactionApiClient(IApiClientTransport client, IApiClientSerialization public virtual async Task> PostTransactionAsync( PostTransactionBody body) { - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PostAsync(_transactionApiPath, content)) { var stream = await response.Content.ReadAsStreamAsync(); diff --git a/arangodb-net-standard/UserApi/UserApiClient.cs b/arangodb-net-standard/UserApi/UserApiClient.cs index 0a67c88b..f6dac197 100644 --- a/arangodb-net-standard/UserApi/UserApiClient.cs +++ b/arangodb-net-standard/UserApi/UserApiClient.cs @@ -55,7 +55,7 @@ public UserApiClient(IApiClientTransport client, IApiClientSerialization seriali /// public virtual async Task PostUserAsync(PostUserBody body) { - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PostAsync(_userApiPath, content)) { if (response.IsSuccessStatusCode) @@ -78,7 +78,7 @@ public virtual async Task PostUserAsync(PostUserBody body) public virtual async Task PutUserAsync(string username, PutUserBody body) { string uri = _userApiPath + '/' + username; - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -101,7 +101,7 @@ public virtual async Task PutUserAsync(string username, PutUser public virtual async Task PatchUserAsync(string username, PatchUserBody body) { string uri = _userApiPath + '/' + username; - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -169,7 +169,7 @@ public virtual async Task PutDatabaseAccessLevelAsync( { string uri = _userApiPath + "/" + WebUtility.UrlEncode(username) + "/database/" + WebUtility.UrlEncode(dbName); - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -275,7 +275,7 @@ public virtual async Task PutCollectionAccessLevelAsync( string uri = _userApiPath + "/" + WebUtility.UrlEncode(username) + "/database/" + WebUtility.UrlEncode(dbName) + "/" + WebUtility.UrlEncode(collectionName); - var content = GetContent(body, true, true); + var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) From 5461085a52acf879001373231e8f4dcd62459c66 Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Thu, 8 Oct 2020 16:27:47 +0100 Subject: [PATCH 02/13] Fixed typos and removed unnecessary interfaces --- arangodb-net-standard/ApiClientBase.cs | 4 ++-- .../CursorApi/CursorApiClient.cs | 4 ++-- .../CursorApi/ICursorApiClient.cs | 4 ++-- .../DocumentApi/DocumentApiClient.cs | 14 +++++++------- .../DocumentApi/IDocumentApiClient.cs | 14 +++++++------- arangodb-net-standard/GraphApi/GraphApiClient.cs | 8 ++++---- arangodb-net-standard/GraphApi/IGraphApiClient.cs | 8 ++++---- .../Serialization/ApiClientSerialization.cs | 11 ++++++----- .../ApiClientSerializationOptions.cs | 8 ++++---- .../Serialization/IApiClientSerialization.cs | 10 +++------- .../IApiClientSerializationOptions.cs | 12 ------------ .../JsonNetApiClientSerialization.cs | 15 +++++++++------ 12 files changed, 50 insertions(+), 62 deletions(-) delete mode 100644 arangodb-net-standard/Serialization/IApiClientSerializationOptions.cs diff --git a/arangodb-net-standard/ApiClientBase.cs b/arangodb-net-standard/ApiClientBase.cs index c718c4ae..28dcfd76 100644 --- a/arangodb-net-standard/ApiClientBase.cs +++ b/arangodb-net-standard/ApiClientBase.cs @@ -66,11 +66,11 @@ protected T DeserializeJsonFromStream(Stream stream) } } - protected byte[] GetContent(T item, IApiClientSerializationOptions options) + protected byte[] GetContent(T item, ApiClientSerializationOptions serializationOptions) { try { - return _serialization.Serialize(item, options); + return _serialization.Serialize(item, serializationOptions); } catch (Exception e) { diff --git a/arangodb-net-standard/CursorApi/CursorApiClient.cs b/arangodb-net-standard/CursorApi/CursorApiClient.cs index cddcf38d..95df5f7b 100644 --- a/arangodb-net-standard/CursorApi/CursorApiClient.cs +++ b/arangodb-net-standard/CursorApi/CursorApiClient.cs @@ -68,7 +68,7 @@ public virtual async Task> PostCursorAsync( bool? cache = null, long? memoryLimit = null, int? ttl = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { return await PostCursorAsync(new PostCursorBody { @@ -91,7 +91,7 @@ public virtual async Task> PostCursorAsync( /// public virtual async Task> PostCursorAsync( PostCursorBody postCursorBody, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { var content = GetContent(postCursorBody, serializationOptions); using (var response = await _client.PostAsync(_cursorApiPath, content)) diff --git a/arangodb-net-standard/CursorApi/ICursorApiClient.cs b/arangodb-net-standard/CursorApi/ICursorApiClient.cs index b5f7a651..96055be7 100644 --- a/arangodb-net-standard/CursorApi/ICursorApiClient.cs +++ b/arangodb-net-standard/CursorApi/ICursorApiClient.cs @@ -32,7 +32,7 @@ Task> PostCursorAsync( bool? cache = null, long? memoryLimit = null, int? ttl = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Execute an AQL query, creating a cursor which can be used to page query results. @@ -41,7 +41,7 @@ Task> PostCursorAsync( /// Task> PostCursorAsync( PostCursorBody postCursorBody, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Deletes an existing cursor and frees the resources associated with it. diff --git a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs index c2264425..b1b3f9c1 100644 --- a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs @@ -58,7 +58,7 @@ public virtual async Task> PostDocumentAsync( string collectionName, T document, PostDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { string uriString = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) @@ -90,7 +90,7 @@ public virtual async Task> PostDocumentsAsync( string collectionName, IList documents, PostDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { string uriString = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) @@ -129,7 +129,7 @@ public virtual async Task> PutDocumentsAsync( string collectionName, IList documents, PutDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) @@ -170,7 +170,7 @@ public virtual async Task> PutDocumentAsync( string documentId, T doc, PutDocumentQuery opts = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { ValidateDocumentId(documentId); string uri = _docApiPath + "/" + documentId; @@ -397,7 +397,7 @@ public virtual async Task> DeleteDocumentsAsync( string collectionName, IList selectors, DeleteDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) @@ -450,7 +450,7 @@ public virtual async Task> PatchDocumentsAsync( string collectionName, IList patches, PatchDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) @@ -528,7 +528,7 @@ public virtual async Task> PatchDocumentAsync( string documentId, T body, PatchDocumentQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { ValidateDocumentId(documentId); string uriString = _docApiPath + "/" + documentId; diff --git a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs index 0961342e..76e05bf4 100644 --- a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs @@ -24,7 +24,7 @@ Task> PostDocumentAsync( string collectionName, T document, PostDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Post multiple documents in a single request. @@ -39,7 +39,7 @@ Task> PostDocumentsAsync( string collectionName, IList documents, PostDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Replace multiple documents. @@ -54,7 +54,7 @@ Task> PutDocumentsAsync( string collectionName, IList documents, PutDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Replaces the document with the provided document ID with the one in @@ -71,7 +71,7 @@ Task> PutDocumentAsync( string documentId, T doc, PutDocumentQuery opts = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Replaces the document based on its Document ID with the one in @@ -209,7 +209,7 @@ Task> DeleteDocumentsAsync( string collectionName, IList selectors, DeleteDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Partially updates documents, the documents to update are specified @@ -239,7 +239,7 @@ Task> PatchDocumentsAsync( string collectionName, IList patches, PatchDocumentsQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Partially updates the document identified by document-handle. @@ -286,7 +286,7 @@ Task> PatchDocumentAsync( string documentId, T body, PatchDocumentQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Like GET, but only returns the header fields and not the body. You diff --git a/arangodb-net-standard/GraphApi/GraphApiClient.cs b/arangodb-net-standard/GraphApi/GraphApiClient.cs index cc622b7c..162a9e8c 100644 --- a/arangodb-net-standard/GraphApi/GraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/GraphApiClient.cs @@ -262,7 +262,7 @@ public virtual async Task> PostVertexAsync( string collectionName, T vertex, PostVertexQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { string uri = _graphApiPath + '/' + WebUtility.UrlEncode(graphName) + "/vertex/" + WebUtility.UrlEncode(collectionName); @@ -368,7 +368,7 @@ public virtual async Task> PostEdgeAsync( string collectionName, T edge, PostEdgeQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { var content = GetContent(edge, serializationOptions); @@ -634,7 +634,7 @@ public virtual Task> PatchVertexAsync( string vertexKey, T body, PatchVertexQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { return PatchVertexAsync( graphName, @@ -663,7 +663,7 @@ public virtual async Task> PatchVertexAsync( string documentId, T body, PatchVertexQuery query = null, - IApiClientSerializationOptions serializationOptions = null) + ApiClientSerializationOptions serializationOptions = null) { ValidateDocumentId(documentId); diff --git a/arangodb-net-standard/GraphApi/IGraphApiClient.cs b/arangodb-net-standard/GraphApi/IGraphApiClient.cs index 495160a4..b10a058a 100644 --- a/arangodb-net-standard/GraphApi/IGraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/IGraphApiClient.cs @@ -114,7 +114,7 @@ Task> PostVertexAsync( string collectionName, T vertex, PostVertexQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Remove one edge definition from the graph. This will only remove the @@ -168,7 +168,7 @@ Task> PostEdgeAsync( string collectionName, T edge, PostEdgeQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Gets an edge from the given graph using the edge collection and _key attribute. @@ -305,7 +305,7 @@ Task> PatchVertexAsync( string vertexKey, T body, PatchVertexQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Updates the data of the specific vertex based on its document ID. @@ -325,7 +325,7 @@ Task> PatchVertexAsync( string documentId, T body, PatchVertexQuery query = null, - IApiClientSerializationOptions serializationOptions = null); + ApiClientSerializationOptions serializationOptions = null); /// /// Replaces the data of an edge in the collection. diff --git a/arangodb-net-standard/Serialization/ApiClientSerialization.cs b/arangodb-net-standard/Serialization/ApiClientSerialization.cs index 25840a1f..3a3aa831 100644 --- a/arangodb-net-standard/Serialization/ApiClientSerialization.cs +++ b/arangodb-net-standard/Serialization/ApiClientSerialization.cs @@ -3,15 +3,15 @@ namespace ArangoDBNetStandard.Serialization { /// - /// The Api client serilization abastract class. - /// Used as a base to implement custom serilizations. + /// The Api client serialization abastract class. + /// Used as a base to implement custom serialization. /// public abstract class ApiClientSerialization : IApiClientSerialization { /// /// The default serialization options. /// - public abstract IApiClientSerializationOptions DefaultOptions { get; } + protected virtual ApiClientSerializationOptions DefaultOptions => new ApiClientSerializationOptions(true, true); /// /// Deserializes the data structure contained by the specified stream @@ -28,8 +28,9 @@ public abstract class ApiClientSerialization : IApiClientSerialization /// /// The type of the object to serialize. /// The object to serialize. - /// The serialization content type. + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// - public abstract byte[] Serialize(T item, IApiClientSerializationOptions options); + public abstract byte[] Serialize(T item, ApiClientSerializationOptions serializationOptions); } } diff --git a/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs b/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs index 06b56507..26fb4d6f 100644 --- a/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs +++ b/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs @@ -1,18 +1,18 @@ namespace ArangoDBNetStandard.Serialization { /// - /// The API client serilization options class. + /// The API client serialization options class. /// - public class ApiClientSerializationOptions : IApiClientSerializationOptions + public class ApiClientSerializationOptions { /// - /// Use camlel case if true, otherwise depends on + /// Use camel case if true, otherwise depends on /// the action will be implemented in the serializer. /// public bool UseCamelCasePropertyNames { get; } /// - /// True to ignore values, otherwise false. + /// True to ignore null values, otherwise false. /// public bool IgnoreNullValues { get; } diff --git a/arangodb-net-standard/Serialization/IApiClientSerialization.cs b/arangodb-net-standard/Serialization/IApiClientSerialization.cs index 06968d4b..66d8a8bf 100644 --- a/arangodb-net-standard/Serialization/IApiClientSerialization.cs +++ b/arangodb-net-standard/Serialization/IApiClientSerialization.cs @@ -7,11 +7,6 @@ namespace ArangoDBNetStandard.Serialization /// public interface IApiClientSerialization { - /// - /// The default serialization options. - /// - IApiClientSerializationOptions DefaultOptions { get; } - /// /// Deserializes the data structure contained by the specified stream /// into an instance of the specified type. @@ -27,8 +22,9 @@ public interface IApiClientSerialization /// /// The type of the object to serialize. /// The object to serialize. - /// The serialization content type. + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// - byte[] Serialize(T item, IApiClientSerializationOptions options); + byte[] Serialize(T item, ApiClientSerializationOptions serializationOptions); } } diff --git a/arangodb-net-standard/Serialization/IApiClientSerializationOptions.cs b/arangodb-net-standard/Serialization/IApiClientSerializationOptions.cs deleted file mode 100644 index d61af746..00000000 --- a/arangodb-net-standard/Serialization/IApiClientSerializationOptions.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace ArangoDBNetStandard.Serialization -{ - /// - /// Define the options. - /// - public interface IApiClientSerializationOptions - { - bool IgnoreNullValues { get; } - - bool UseCamelCasePropertyNames { get; } - } -} diff --git a/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs b/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs index 5f3858f2..86398389 100644 --- a/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs +++ b/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs @@ -9,7 +9,10 @@ namespace ArangoDBNetStandard.Serialization /// public class JsonNetApiClientSerialization : ApiClientSerialization { - public override IApiClientSerializationOptions DefaultOptions => new ApiClientSerializationOptions(true, true); + /// + /// The default serialization options. + /// + protected override ApiClientSerializationOptions DefaultOptions => new ApiClientSerializationOptions(true, true); /// /// Deserializes the JSON structure contained by the specified stream @@ -44,20 +47,20 @@ public override T DeserializeFromStream(Stream stream) /// /// - public override byte[] Serialize(T item, IApiClientSerializationOptions options) + public override byte[] Serialize(T item, ApiClientSerializationOptions serializationOptions) { // When no options passed use the default. - if(options == null) + if(serializationOptions == null) { - options = DefaultOptions; + serializationOptions = DefaultOptions; } var jsonSettings = new JsonSerializerSettings { - NullValueHandling = options.IgnoreNullValues ? NullValueHandling.Ignore : NullValueHandling.Include + NullValueHandling = serializationOptions.IgnoreNullValues ? NullValueHandling.Ignore : NullValueHandling.Include }; - if (options.UseCamelCasePropertyNames) + if (serializationOptions.UseCamelCasePropertyNames) { jsonSettings.ContractResolver = new CamelCasePropertyNamesExceptDictionaryContractResolver(); } From bfd82c342049efa175b146fc1bd71c3c450a1644 Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Thu, 8 Oct 2020 16:38:18 +0100 Subject: [PATCH 03/13] Fix variable name improve summary --- .../Serialization/JsonNetApiClientSerialization.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs b/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs index 86398389..45281c46 100644 --- a/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs +++ b/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs @@ -44,7 +44,8 @@ public override T DeserializeFromStream(Stream stream) /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public override byte[] Serialize(T item, ApiClientSerializationOptions serializationOptions) From 2e2e6eeafed904860c27e51cb951dd6a4d9bfd94 Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Fri, 9 Oct 2020 12:34:26 +0100 Subject: [PATCH 04/13] Change to false,true for some endpoints made the optios public --- arangodb-net-standard.Test/Docs/UsageTest.cs | 2 +- arangodb-net-standard/CursorApi/CursorApiClient.cs | 2 +- .../Serialization/ApiClientSerialization.cs | 2 +- .../Serialization/ApiClientSerializationOptions.cs | 4 ++-- .../Serialization/JsonNetApiClientSerialization.cs | 7 +------ 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/arangodb-net-standard.Test/Docs/UsageTest.cs b/arangodb-net-standard.Test/Docs/UsageTest.cs index c65cb09a..0a5acc9b 100644 --- a/arangodb-net-standard.Test/Docs/UsageTest.cs +++ b/arangodb-net-standard.Test/Docs/UsageTest.cs @@ -105,7 +105,7 @@ await adb.Document.PostDocumentAsync( // Run AQL query (create a query cursor) var response = await adb.Cursor.PostCursorAsync( @"FOR doc IN MyCollection - FILTER doc.itemNumber == 123456 + FILTER doc.ItemNumber == 123456 RETURN doc"); MyClassDocument item = response.Result.First(); diff --git a/arangodb-net-standard/CursorApi/CursorApiClient.cs b/arangodb-net-standard/CursorApi/CursorApiClient.cs index 95df5f7b..6933b152 100644 --- a/arangodb-net-standard/CursorApi/CursorApiClient.cs +++ b/arangodb-net-standard/CursorApi/CursorApiClient.cs @@ -93,7 +93,7 @@ public virtual async Task> PostCursorAsync( PostCursorBody postCursorBody, ApiClientSerializationOptions serializationOptions = null) { - var content = GetContent(postCursorBody, serializationOptions); + var content = GetContent(postCursorBody, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PostAsync(_cursorApiPath, content)) { if (response.IsSuccessStatusCode) diff --git a/arangodb-net-standard/Serialization/ApiClientSerialization.cs b/arangodb-net-standard/Serialization/ApiClientSerialization.cs index 3a3aa831..58dcc2e6 100644 --- a/arangodb-net-standard/Serialization/ApiClientSerialization.cs +++ b/arangodb-net-standard/Serialization/ApiClientSerialization.cs @@ -11,7 +11,7 @@ public abstract class ApiClientSerialization : IApiClientSerialization /// /// The default serialization options. /// - protected virtual ApiClientSerializationOptions DefaultOptions => new ApiClientSerializationOptions(true, true); + public virtual ApiClientSerializationOptions DefaultOptions => new ApiClientSerializationOptions(false, true); /// /// Deserializes the data structure contained by the specified stream diff --git a/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs b/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs index 26fb4d6f..11cfc1c3 100644 --- a/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs +++ b/arangodb-net-standard/Serialization/ApiClientSerializationOptions.cs @@ -9,12 +9,12 @@ public class ApiClientSerializationOptions /// Use camel case if true, otherwise depends on /// the action will be implemented in the serializer. /// - public bool UseCamelCasePropertyNames { get; } + public bool UseCamelCasePropertyNames { get; set; } /// /// True to ignore null values, otherwise false. /// - public bool IgnoreNullValues { get; } + public bool IgnoreNullValues { get; set; } /// /// diff --git a/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs b/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs index 45281c46..647e6bcd 100644 --- a/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs +++ b/arangodb-net-standard/Serialization/JsonNetApiClientSerialization.cs @@ -9,11 +9,6 @@ namespace ArangoDBNetStandard.Serialization /// public class JsonNetApiClientSerialization : ApiClientSerialization { - /// - /// The default serialization options. - /// - protected override ApiClientSerializationOptions DefaultOptions => new ApiClientSerializationOptions(true, true); - /// /// Deserializes the JSON structure contained by the specified stream /// into an instance of the specified type. @@ -51,7 +46,7 @@ public override T DeserializeFromStream(Stream stream) public override byte[] Serialize(T item, ApiClientSerializationOptions serializationOptions) { // When no options passed use the default. - if(serializationOptions == null) + if (serializationOptions == null) { serializationOptions = DefaultOptions; } From fb51ee273982067b5ef692165abe74134b43474a Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Fri, 9 Oct 2020 12:40:12 +0100 Subject: [PATCH 05/13] Minor update --- arangodb-net-standard/CursorApi/CursorApiClient.cs | 12 +++++------- arangodb-net-standard/CursorApi/ICursorApiClient.cs | 6 ++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/arangodb-net-standard/CursorApi/CursorApiClient.cs b/arangodb-net-standard/CursorApi/CursorApiClient.cs index 6933b152..72f8a382 100644 --- a/arangodb-net-standard/CursorApi/CursorApiClient.cs +++ b/arangodb-net-standard/CursorApi/CursorApiClient.cs @@ -57,7 +57,8 @@ public CursorApiClient(IApiClientTransport client, IApiClientSerialization seria /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PostCursorAsync( string query, @@ -67,8 +68,7 @@ public virtual async Task> PostCursorAsync( long? batchSize = null, bool? cache = null, long? memoryLimit = null, - int? ttl = null, - ApiClientSerializationOptions serializationOptions = null) + int? ttl = null) { return await PostCursorAsync(new PostCursorBody { @@ -80,18 +80,16 @@ public virtual async Task> PostCursorAsync( Cache = cache, MemoryLimit = memoryLimit, Ttl = ttl - }, serializationOptions); + }); } /// /// Execute an AQL query, creating a cursor which can be used to page query results. /// /// Object encapsulating options and parameters of the query. - /// /// public virtual async Task> PostCursorAsync( - PostCursorBody postCursorBody, - ApiClientSerializationOptions serializationOptions = null) + PostCursorBody postCursorBody) { var content = GetContent(postCursorBody, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PostAsync(_cursorApiPath, content)) diff --git a/arangodb-net-standard/CursorApi/ICursorApiClient.cs b/arangodb-net-standard/CursorApi/ICursorApiClient.cs index 96055be7..0df0e628 100644 --- a/arangodb-net-standard/CursorApi/ICursorApiClient.cs +++ b/arangodb-net-standard/CursorApi/ICursorApiClient.cs @@ -31,8 +31,7 @@ Task> PostCursorAsync( long? batchSize = null, bool? cache = null, long? memoryLimit = null, - int? ttl = null, - ApiClientSerializationOptions serializationOptions = null); + int? ttl = null); /// /// Execute an AQL query, creating a cursor which can be used to page query results. @@ -40,8 +39,7 @@ Task> PostCursorAsync( /// Object encapsulating options and parameters of the query. /// Task> PostCursorAsync( - PostCursorBody postCursorBody, - ApiClientSerializationOptions serializationOptions = null); + PostCursorBody postCursorBody); /// /// Deletes an existing cursor and frees the resources associated with it. From bbb98b17766ecbabc8a1fa9d0cd77a6e1803d1ce Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Fri, 9 Oct 2020 12:44:00 +0100 Subject: [PATCH 06/13] Remove extra input options from DeleteDocuments --- arangodb-net-standard/DocumentApi/DocumentApiClient.cs | 6 ++---- arangodb-net-standard/DocumentApi/IDocumentApiClient.cs | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs index b1b3f9c1..631455c4 100644 --- a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs @@ -391,20 +391,18 @@ public virtual async Task> DeleteDocumentsAsync( /// /// /// - /// /// public virtual async Task> DeleteDocumentsAsync( string collectionName, IList selectors, - DeleteDocumentsQuery query = null, - ApiClientSerializationOptions serializationOptions = null) + DeleteDocumentsQuery query = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } - var content = GetContent(selectors, serializationOptions); + var content = GetContent(selectors, new ApiClientSerializationOptions(false, false)); using (var response = await _client.DeleteAsync(uri, content)) { if (response.IsSuccessStatusCode) diff --git a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs index 76e05bf4..b0c12417 100644 --- a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs @@ -208,8 +208,7 @@ Task> DeleteDocumentsAsync( Task> DeleteDocumentsAsync( string collectionName, IList selectors, - DeleteDocumentsQuery query = null, - ApiClientSerializationOptions serializationOptions = null); + DeleteDocumentsQuery query = null); /// /// Partially updates documents, the documents to update are specified From be731e06aa850bdbb9c36fa963bdd1f42d01f764 Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Fri, 9 Oct 2020 12:53:28 +0100 Subject: [PATCH 07/13] Fix options --- arangodb-net-standard/GraphApi/GraphApiClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arangodb-net-standard/GraphApi/GraphApiClient.cs b/arangodb-net-standard/GraphApi/GraphApiClient.cs index 162a9e8c..78d08a84 100644 --- a/arangodb-net-standard/GraphApi/GraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/GraphApiClient.cs @@ -675,7 +675,7 @@ public virtual async Task> PatchVertexAsync( uri += "?" + query.ToQueryString(); } - var content = GetContent(body, new ApiClientSerializationOptions(true, true)); + var content = GetContent(body, new ApiClientSerializationOptions(false, false)); using (var response = await _transport.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) @@ -738,7 +738,7 @@ public virtual async Task> PutEdgeAsync( uri += "?" + query.ToQueryString(); } - var content = GetContent(edge, new ApiClientSerializationOptions(true, true)); + var content = GetContent(edge, new ApiClientSerializationOptions(false,false)); using (var response = await _transport.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) From 5a66eee82fed464dbc654a677682480907f7745d Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Fri, 9 Oct 2020 13:01:59 +0100 Subject: [PATCH 08/13] Remove extra method inputs --- arangodb-net-standard/GraphApi/GraphApiClient.cs | 10 +++------- arangodb-net-standard/GraphApi/IGraphApiClient.cs | 7 ++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/arangodb-net-standard/GraphApi/GraphApiClient.cs b/arangodb-net-standard/GraphApi/GraphApiClient.cs index 78d08a84..75f07c10 100644 --- a/arangodb-net-standard/GraphApi/GraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/GraphApiClient.cs @@ -633,15 +633,13 @@ public virtual Task> PatchVertexAsync( string collectionName, string vertexKey, T body, - PatchVertexQuery query = null, - ApiClientSerializationOptions serializationOptions = null) + PatchVertexQuery query = null) { return PatchVertexAsync( graphName, WebUtility.UrlEncode(collectionName) + "/" + WebUtility.UrlEncode(vertexKey), body, - query, - serializationOptions); + query); } /// @@ -656,14 +654,12 @@ public virtual Task> PatchVertexAsync( /// The document ID of the vertex to update. /// /// - /// /// public virtual async Task> PatchVertexAsync( string graphName, string documentId, T body, - PatchVertexQuery query = null, - ApiClientSerializationOptions serializationOptions = null) + PatchVertexQuery query = null) { ValidateDocumentId(documentId); diff --git a/arangodb-net-standard/GraphApi/IGraphApiClient.cs b/arangodb-net-standard/GraphApi/IGraphApiClient.cs index b10a058a..0218bf84 100644 --- a/arangodb-net-standard/GraphApi/IGraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/IGraphApiClient.cs @@ -297,15 +297,13 @@ Task> DeleteVertexAsync( /// /// /// - /// /// Task> PatchVertexAsync( string graphName, string collectionName, string vertexKey, T body, - PatchVertexQuery query = null, - ApiClientSerializationOptions serializationOptions = null); + PatchVertexQuery query = null); /// /// Updates the data of the specific vertex based on its document ID. @@ -324,8 +322,7 @@ Task> PatchVertexAsync( string graphName, string documentId, T body, - PatchVertexQuery query = null, - ApiClientSerializationOptions serializationOptions = null); + PatchVertexQuery query = null); /// /// Replaces the data of an edge in the collection. From d18ad81e3c0aa6ce2a1ee8d5b6e9d7f6bb6d3933 Mon Sep 17 00:00:00 2001 From: Ross Mills Date: Fri, 9 Oct 2020 13:17:08 +0100 Subject: [PATCH 09/13] Update readme for new serializer options. --- readme.md | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/readme.md b/readme.md index 8613b5e0..89453b8b 100644 --- a/readme.md +++ b/readme.md @@ -17,10 +17,11 @@ A consistent, comprehensive, minimal driver for the [ArangoDB REST API](https:// - [Create a database](#create-a-database) - [Create a collection](#create-a-collection) - [Create documents](#create-documents) - * [Side note on document keys](#side-note-on-document-keys) + - [Side note on document keys](#side-note-on-document-keys) - [Run an AQL query](#run-an-aql-query) - [Patch a document](#patch-a-document) - [Replace a document](#replace-a-document) + + [Serialization Options](#serialization-options) + [API Errors](#api-errors) + [Project Conventions](#project-conventions) - [Overall project structure](#overall-project-structure) @@ -132,35 +133,13 @@ await adb.Document.PostDocumentAsync( }); ``` -##### Side note on document keys +#### Side note on document keys -The document object must not have any `_key` property if you expect ArangoDB to generate the document key for you. For our examples here, we've used a separate class for creating documents vs fetching them. +The document object must not have any value against a property named `_key` if you expect ArangoDB to generate the document key for you. -`MyClass` has no `_key` property: +The default serializer options specify that null values will be ignored, so if your class has a `_key` property, you can leave it as `null` when creating a new document. -```csharp -class MyClass -{ - public long ItemNumber { get; set; } - - public string Description { get; set; } -} -``` - - `MyClassDocument` is a subclass of `MyClass` which does define the `_key` property, along with `_id` and `_rev`. - -```csharp -class MyClassDocument: MyClass -{ - public string _key { get; set; } - - public string _id { get; set; } - - public string _rev { get; set; } -} -``` - -You may or may not find this pattern useful in your own application. +If you change the serializer options so that `IgnoreNullValues` is `false` then you cannot create a new document using a class the specifies a property named `_key`, because the ArangoDB API will reject the request. #### Run an AQL query @@ -194,6 +173,22 @@ await adb.Document.PutDocumentAsync( item); ``` +### Serialization Options + +All API methods that support passing objects of user-specified data types have an optional method argument to pass in custom serialization options. These options can be used to control the behaviour of the underlying serializer implementation. + +The options are passed as an instance of the `ApiClientSerializationOptions` class, which contains options for: + +- `boolean UseCamelCasePropertyNames` +- `boolean IgnoreNullValues` + +In addition, the default options can be updated, which will affect all subsequent operations that use these options. To set default options, set them on the serializer implementation itself. For example, if using the supplied `JsonNetApiClientSerialization`: + +``` +var serializer = new JsonNetApiClientSerialization(); +serializer.DefaultOptions.IgnoreNullValues = false; +``` + ### API Errors Any time an endpoint responds with an HTTP status code which is not a "success" code, an `ApiErrorException` will be thrown. You may wish to wrap your API calls in a try/catch block, and catch `ApiErrorException` in certain circumstances. @@ -349,7 +344,7 @@ var docResponse = await adb.Document.PostDocumentAsync( ArangoDB-net-standard allows for alternative serializer implementations to be used by implementing the `IApiClientSerialization` interface. By default, all API clients will use the provided `JsonNetApiClientSerialization` which uses the Json.NET library. To use an alternative serialization implementation, pass an instance of `IApiClientSerialization` when instantiating any API client class or the `ArangoDBClient` class. -In many cases we depend on the behaviour of Json.NET to automatically map JSON properties using `camelCase` to C# properties defined using `PascalCase` when deserializing. Any alternative serializer will need to mimic that behaviour in order to deserialize some ArangoDB JSON objects to their C# types. +In many cases we depend on the behaviour of Json.NET to automatically map JSON properties using `camelCase` to C# properties defined using `PascalCase` when deserializing. Any alternative serializer will need to mimic that behaviour in order to deserialize some ArangoDB JSON objects to their C# types. For example, if using `System.Text.Json`, the option `PropertyNameCaseInsensitive = true` should be used. ## Contributing From 10e4342965ab3db1e017b0fb12d77e7e60d3583a Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Fri, 9 Oct 2020 13:17:56 +0100 Subject: [PATCH 10/13] Fix summaries --- .../CursorApi/CursorApiClient.cs | 2 -- .../DocumentApi/DocumentApiClient.cs | 19 ++++++++++++------- .../DocumentApi/IDocumentApiClient.cs | 15 ++++++++++----- .../GraphApi/GraphApiClient.cs | 7 ++++--- .../GraphApi/IGraphApiClient.cs | 7 ++++--- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/arangodb-net-standard/CursorApi/CursorApiClient.cs b/arangodb-net-standard/CursorApi/CursorApiClient.cs index 72f8a382..8ac7f5e4 100644 --- a/arangodb-net-standard/CursorApi/CursorApiClient.cs +++ b/arangodb-net-standard/CursorApi/CursorApiClient.cs @@ -57,8 +57,6 @@ public CursorApiClient(IApiClientTransport client, IApiClientSerialization seria /// /// /// - /// The serialization options. When the value is null the - /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PostCursorAsync( string query, diff --git a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs index 631455c4..bb04fb90 100644 --- a/arangodb-net-standard/DocumentApi/DocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/DocumentApiClient.cs @@ -52,7 +52,8 @@ public DocumentApiClient(IApiClientTransport client, IApiClientSerialization ser /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PostDocumentAsync( string collectionName, @@ -84,7 +85,8 @@ public virtual async Task> PostDocumentAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PostDocumentsAsync( string collectionName, @@ -123,7 +125,8 @@ public virtual async Task> PostDocumentsAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PutDocumentsAsync( string collectionName, @@ -163,8 +166,8 @@ public virtual async Task> PutDocumentsAsync( /// /// /// - /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PutDocumentAsync( string documentId, @@ -442,7 +445,8 @@ public virtual async Task> DeleteDocumentsAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PatchDocumentsAsync( string collectionName, @@ -520,7 +524,8 @@ public virtual async Task> PatchDocumentAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PatchDocumentAsync( string documentId, diff --git a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs index b0c12417..24377efe 100644 --- a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs @@ -18,7 +18,8 @@ public interface IDocumentApiClient /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> PostDocumentAsync( string collectionName, @@ -33,7 +34,8 @@ Task> PostDocumentAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> PostDocumentsAsync( string collectionName, @@ -48,7 +50,8 @@ Task> PostDocumentsAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> PutDocumentsAsync( string collectionName, @@ -65,7 +68,8 @@ Task> PutDocumentsAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> PutDocumentAsync( string documentId, @@ -189,7 +193,8 @@ Task> DeleteDocumentAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> DeleteDocumentsAsync( string collectionName, diff --git a/arangodb-net-standard/GraphApi/GraphApiClient.cs b/arangodb-net-standard/GraphApi/GraphApiClient.cs index 75f07c10..a4779228 100644 --- a/arangodb-net-standard/GraphApi/GraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/GraphApiClient.cs @@ -255,7 +255,8 @@ public virtual async Task PostVertexCollectionAsyn /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PostVertexAsync( string graphName, @@ -361,7 +362,8 @@ public virtual async Task DeleteVertexCollection /// The name of the edge collection the edge belongs to. /// The edge to create. /// Optional query parameters of the request. - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// public virtual async Task> PostEdgeAsync( string graphName, @@ -626,7 +628,6 @@ public virtual async Task> DeleteVertexAsync( /// /// /// - /// /// public virtual Task> PatchVertexAsync( string graphName, diff --git a/arangodb-net-standard/GraphApi/IGraphApiClient.cs b/arangodb-net-standard/GraphApi/IGraphApiClient.cs index 0218bf84..060105c6 100644 --- a/arangodb-net-standard/GraphApi/IGraphApiClient.cs +++ b/arangodb-net-standard/GraphApi/IGraphApiClient.cs @@ -107,7 +107,8 @@ Task PostVertexCollectionAsync( /// /// /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> PostVertexAsync( string graphName, @@ -161,7 +162,8 @@ Task DeleteVertexCollectionAsync( /// The name of the edge collection the edge belongs to. /// The edge to create. /// - /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> PostEdgeAsync( string graphName, @@ -316,7 +318,6 @@ Task> PatchVertexAsync( /// The document ID of the vertex to update. /// /// - /// /// Task> PatchVertexAsync( string graphName, From 4400090d6a5b1a6bdef83444b544ae29c75e96d9 Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Mon, 12 Oct 2020 11:24:44 +0100 Subject: [PATCH 11/13] Remove extra parameter from summary --- arangodb-net-standard/DocumentApi/IDocumentApiClient.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs index 24377efe..33c0c1a4 100644 --- a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs @@ -193,8 +193,6 @@ Task> DeleteDocumentAsync( /// /// /// - /// The serialization options. When the value is null the - /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> DeleteDocumentsAsync( string collectionName, From cd2cb7088c443017567226da11abdd78b7b02d5e Mon Sep 17 00:00:00 2001 From: Anastasios Karangelis Date: Mon, 12 Oct 2020 11:58:29 +0100 Subject: [PATCH 12/13] Add missing params from summary --- arangodb-net-standard/DocumentApi/IDocumentApiClient.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs index 33c0c1a4..2e6c7272 100644 --- a/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs +++ b/arangodb-net-standard/DocumentApi/IDocumentApiClient.cs @@ -236,6 +236,8 @@ Task> DeleteDocumentsAsync( /// /// /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> PatchDocumentsAsync( string collectionName, @@ -283,6 +285,8 @@ Task> PatchDocumentAsync( /// /// /// + /// The serialization options. When the value is null the + /// the serialization options should be provided by the serializer, otherwise the given options should be used. /// Task> PatchDocumentAsync( string documentId, From a2ba8a4ebc0698d77f80fff324c632fa34c177cb Mon Sep 17 00:00:00 2001 From: Pierre-Yves FARE Date: Mon, 12 Oct 2020 13:42:34 +0100 Subject: [PATCH 13/13] Mention abstract class ApiClientSerialization in readme. --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 89453b8b..3cfae7e0 100644 --- a/readme.md +++ b/readme.md @@ -342,7 +342,9 @@ var docResponse = await adb.Document.PostDocumentAsync( ### Serialization -ArangoDB-net-standard allows for alternative serializer implementations to be used by implementing the `IApiClientSerialization` interface. By default, all API clients will use the provided `JsonNetApiClientSerialization` which uses the Json.NET library. To use an alternative serialization implementation, pass an instance of `IApiClientSerialization` when instantiating any API client class or the `ArangoDBClient` class. +ArangoDB-net-standard allows for alternative serializer implementations to be used by implementing the `IApiClientSerialization` interface or `ApiClientSerialization` abstract class. The abstract class provides an additional property for default serialization options to use as fallback when none are provided by the caller. See [Serialization Options](#serialization-options) section above. + +By default, all API clients will use the provided `JsonNetApiClientSerialization` which uses the Json.NET library. To use an alternative serialization implementation, pass an instance of `IApiClientSerialization` when instantiating any API client class or the `ArangoDBClient` class. In many cases we depend on the behaviour of Json.NET to automatically map JSON properties using `camelCase` to C# properties defined using `PascalCase` when deserializing. Any alternative serializer will need to mimic that behaviour in order to deserialize some ArangoDB JSON objects to their C# types. For example, if using `System.Text.Json`, the option `PropertyNameCaseInsensitive = true` should be used.