Skip to content

Commit

Permalink
Tweak formatting of code for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Mar 6, 2023
1 parent 3fe9b4f commit 2350084
Show file tree
Hide file tree
Showing 7 changed files with 360 additions and 334 deletions.
8 changes: 4 additions & 4 deletions docs/client-concepts/client-concepts.asciidoc
@@ -1,19 +1,19 @@
[[client-concepts]]
== Client concepts
= Client concepts

The high-level .NET client for {es} maps closely to the original {es} API. All
The .NET client for {es} maps closely to the original {es} API. All
requests and responses are exposed through types, making it ideal for getting up and running quickly.

[[serialization]]
=== Serialization
== Serialization

By default, the .NET client for {es} uses the Microsoft System.Text.Json library for serialization. The client understands how to serialize and
deserialize the request and response types correctly. It also handles (de)serialization of user POCO types representing documents read or written to {es}.

The client has two distinct serialization responsibilities - serialization of the types owned by the `Elastic.Clients.Elasticsearch` library and serialization of source documents, modeled in application code. The first responsibility is entirely internal; the second is configurable.

[[source-serialization]]
==== Source serialization
=== Source serialization

Source serialization refers to the process of (de)serializing POCO types in consumer applications as source documents indexed and retrieved from {es}. A source serializer implementation handles serialization, with the default implementation using the `System.Text.Json` library. As a result, you may use `System.Text.Json` attributes and converters to control the serialization behavior.

Expand Down
20 changes: 9 additions & 11 deletions docs/client-concepts/serialization/custom-serialization.asciidoc
@@ -1,22 +1,21 @@
[[custom-serialization]]
=== Custom Serialization
==== Custom serialization

The built-in source serializer handles most POCO document models correctly. Sometimes, you may need further control over how your types are serialized.

NOTE: The built-in source serializer uses the Microsoft https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/overview[`System.Text.Json` library] internally. You can apply `System.Text.Json` attributes and converters to control serialization of your document types.

[[system-text-json-attributes]]
==== Using System.Text.Json attributes
===== Using `System.Text.Json` attributes

`System.Text.Json` includes attributes that can be applied to types and properties to control how they are serialized. These can be applied to your POCO document types to perform actions such as controlling the name of a property, or ignoring a property entirely. Visit the https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/overview[Microsoft documentation for further examples].

We can model a document to represent data about a person using a regular class (POCO), applying `System.Text.Json`` attributes as necessary.

[source,csharp]
----
include-tagged::{doc-tests-src}/ClientConcepts/Serialization/CustomSerializationTests.cs[usings-serialization]
include-tagged::{doc-tests-src}/ClientConcepts/Serialization/CustomSerializationTests.cs[person-class-with-attributes]
include::{doc-tests-src}/ClientConcepts/Serialization/CustomSerializationTests.cs[tag=usings-serialization]
include::{doc-tests-src}/ClientConcepts/Serialization/CustomSerializationTests.cs[tag=person-class-with-attributes]
----
<1> the `JsonPropertyName` attribute is used to provide a specific name (`forename`) for the `FirstName` property when serialized.
<2> the `JsonIgnore` attribute is used to prevent the `Age` property from appearing in the serialized JSON.
Expand All @@ -25,9 +24,8 @@ We can then index the an instance of the document into {es}.

[source,csharp]
----
include-tagged::{doc-tests-src}/ClientConcepts/Serialization/CustomSerializationTests.cs[usings]
include-tagged::{doc-tests-src}/ClientConcepts/Serialization/CustomSerializationTests.cs[index-person-with-attributes]
include::{doc-tests-src}/ClientConcepts/Serialization/CustomSerializationTests.cs[tag=usings]
include::{doc-tests-src}/ClientConcepts/Serialization/CustomSerializationTests.cs[tag=index-person-with-attributes]
----

The index request is serialized, with the source serializer handling the `Person` type, serializing the POCO property named `FirstName` to the JSON object member named `forename`. The `Age` property is ignored and does not appear in the JSON.
Expand All @@ -40,17 +38,17 @@ The index request is serialized, with the source serializer handling the `Person
----

[[registering-custom-converters]]
==== Registering custom System.Text.Json converters
===== Registering custom `System.Text.Json` converters

TODO

[[configuring-custom-jsonserializeroptions]]
==== Configuring custom JsonSerializerOptions
===== Configuring custom `JsonSerializerOptions`

TODO

[[injecting-custom-serializer]]
==== Injecting a custom serializer
===== Injecting a custom serializer

TODO
- Deriving from SystemTextJsonSerializer
Expand Down
@@ -1,5 +1,5 @@
[[modeling-documents-with-types]]
=== Modeling documents with types
==== Modeling documents with types

{es} provides search and aggregation capabilities on the documents that it is sent and indexes. These documents are sent as
JSON objects within the request body of a HTTP request. It is natural to model documents within the {es} .NET client using
Expand All @@ -8,7 +8,7 @@ https://en.wikipedia.org/wiki/Plain_Old_CLR_Object[POCOs (__Plain Old CLR Object
This section provides an overview of how types and type hierarchies can be used to model documents.

[[default-behaviour]]
==== Default behaviour
===== Default behaviour

The default behaviour is to serialize type property names as camelcase JSON object members.

Expand All @@ -24,7 +24,6 @@ We can then index the an instance of the document into {es}.
[source,csharp]
----
include-tagged::{doc-tests-src}/ClientConcepts/Serialization/ModellingDocumentsWithTypesTests.cs[usings]
include-tagged::{doc-tests-src}/ClientConcepts/Serialization/ModellingDocumentsWithTypesTests.cs[index-my-document]
----

Expand Down
3 changes: 2 additions & 1 deletion exclusion.dic
Expand Up @@ -2,4 +2,5 @@ deserialize
json
async
inferrer
elasticsearch
elasticsearch
asciidocs
2 changes: 2 additions & 0 deletions tests/Tests/Documentation/.editorconfig
@@ -0,0 +1,2 @@
[*]
indent_style = space

0 comments on commit 2350084

Please sign in to comment.