You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We want to serialize our source document using Pascal Casing for the JSON properties. Since the options applied in the `DefaultSouceSerializer` set the `PropertyNamingPolicy` to `JsonNamingPolicy.CamelCase`, we must override this setting.
59
+
We want to serialize our source document using Pascal Casing for the JSON properties. Since the options applied in the `DefaultSouceSerializer` set the `PropertyNamingPolicy` to `JsonNamingPolicy.CamelCase`, we must override this setting. After configuring the `ElasticsearchClientSettings` we can index our document to {es}.
65
60
66
61
[source,csharp]
67
62
----
@@ -92,6 +87,49 @@ As an alternative to using a local function, we could store an `Action<JsonSeria
In certain more advanced situations, you may have types which require further customization during serialization than is possible using `System.Text.Json` property attributes. In these cases, the recommendation from Microsoft is to leverage a custom `JsonConverter`. Source document types serialized using the `DefaultSourceSerializer` can leverage the power of custom converters.
94
+
95
+
For the example, we have a document class in our application which should use a legacy JSON structure to continue operating with existing indexed documents. Several options are available, but we'll apply a custom converter in this case.
96
+
97
+
Our class is defined and the `JsonConverter` attribute is applied to the class type, specifying the type of a custom converter.
<1> The `JsonConverter` is used to signal to `System.Text.Json` that it should use a converter of type `CustomerConverter` when serializing instances of this class.
105
+
106
+
When serializing this class, rather than include a string value representing the value of the `CustomerType` property, we are required to send a boolean property named `isStandard`. This requirement can be achieved with a custom JsonConverter implementation.
0 commit comments