# Request Serialization in NEST 6

**URL:** <https://discuss.elastic.co/t/request-serialization-in-nest-6/147615>\
**Category:** Elasticsearch\
**Created:** [September 6, 2018, 5:03pm UTC](https://discuss.elastic.co/t/request-serialization-in-nest-6/147615 "2018-09-06T17:03:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thespatt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thespatt/32/7979_2.png) [@thespatt](https://discuss.elastic.co/u/thespatt)\
**Post date:** [September 6, 2018, 5:03pm UTC](https://discuss.elastic.co/t/request-serialization-in-nest-6/147615/1 "2018-09-06T17:03:23Z")

</div>

I used to be able to log the output of the old Client.Serializer and paste it right into Dev Tools in Kibana 5.x and earlier. Now SourceSerializer.SerializeToString outputs all possible fields with null values and pasting it into Dev Tools results in parsing errors. I am able to get the old output I was expecting if I get the RequestBodyInBytes from the response.ApiCall, but I need the request without executing it for our saved searches architecture (sins of the past).

Thanks for any assistance you can offer.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [September 8, 2018, 12:53am UTC](https://discuss.elastic.co/t/request-serialization-in-nest-6/147615/2 "2018-09-08T00:53:08Z")

</div>

Hey @thespatt

The `RequestResponseSerializer` on `IElasticClient` is the one to use for this purpose

```auto
public class MyDocument 
{
    public MyDocument(int id) => Id = id; 
    public int Id { get; set; }      
    public string Message { get; set; }
}

var client = new ElasticClient();

var search = new SearchDescriptor<MyDocument>()
	.Query(q => q
		.Match(m => m
			.Field(f => f.Message)
			.Query("is it me you're looking for?")
		)
	);
	
var json = client.RequestResponseSerializer.SerializeToString(search);

Console.WriteLine(json);

```

which writes out

```json
{
  "query": {
    "match": {
      "message": {
        "query": "is it me you're looking for?"
      }
    }
  }
}

```

In NEST 6.x, with the [internalization and renamespacing of Json.NET](https://www.elastic.co/blog/nest-elasticsearch-net-6-0-ga), a distinction was made between the serializer to use for NEST request and response types, and the one to use for properties that relate to types that you control, for example, `_source` in responses, `terms` input to terms query, etc. With this distinction and separation, there are two serializer properties exposed on `IElasticClient`:

1. `RequestResponseSerializer`

2. `SourceSerializer`

With default serialization, both properties will actually use the same serializer, but when [custom serialization is used](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/custom-serialization.html), the `SourceSerializer` will be assigned with custom serializer hooked up, such as `JsonNetSerializer`.

One of the side effects of the internalizing of [Json.NET](http://Json.NET) is that by default, NEST now has no knowledge of how to serialize [Json.NET](http://Json.NET) types such as `JObject`, `JArray`, etc. because the types internally are renamespaced, making them different types. To allow serialization of these types to work as before, and allow users to define their own [Json.NET](http://Json.NET) serialization settings without affecting NEST, the [nuget package NEST.JsonNetSerializer](https://www.nuget.org/packages/NEST.JsonNetSerializer/) can be used and the [JsonNetSerializer hooked up as the serializer.](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/custom-serialization.html#_jsonnetserializer).

There is much more that we aim to do with serialization of which internalizing [Json.NET](http://Json.NET) is the first step!

---

<div class="post-metadata">

**Author:** ![thespatt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thespatt/32/7979_2.png) [@thespatt](https://discuss.elastic.co/u/thespatt)\
**Post date:** [September 8, 2018, 3:36am UTC](https://discuss.elastic.co/t/request-serialization-in-nest-6/147615/3 "2018-09-08T03:36:26Z")

</div>

@forloop Thanks, I can't believe I missed that. I had it at one time but must have changed it. In any case thanks for the great explanation it's exactly what I needed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 6, 2018, 3:36am UTC](https://discuss.elastic.co/t/request-serialization-in-nest-6/147615/4 "2018-10-06T03:36:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
