Skip to content

elastic.RequestResponseSerializer.Deserialize<CreateIndexRequestDescriptor>(stream) fails with: read too much or not enough #7969

@dlukyanov

Description

@dlukyanov

Elastic.Clients.Elasticsearch version: 8.10

Elasticsearch version: 8

.NET runtime version: 6

Operating system version: windows10

Not sure if it's a problem, but my goal to externalize index mapping definition - I want to read it from a file.

Tried to use ElasticsearchClient.RequestResponseSerializer.Deserialize<CreateIndexRequestDescriptor>(stream)

However it throws exception:

System.Text.Json.JsonException: The converter 'System.Text.Json.Serialization.Converters.CastingConverter`
  2[Elastic.Clients.Elasticsearch.IndexManagement.CreateIndexRequestDescriptor,Elastic.Clients.Elasticsearch.Serialization.ISelfSerializable]' 
  read too much or not enough. Path: $ | LineNumber: 0 | BytePositionInLine: 1.
   at System.Text.Json.ThrowHelper.ThrowJsonException_SerializationConverterRead(JsonConverter converter)
   at System.Text.Json.Serialization.JsonConverter`1.VerifyRead(JsonTokenType tokenType, Int32 depth, Int64 bytesConsumed, Boolean isValueConverter, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.ReadFromStream[TValue](Stream utf8Json, JsonTypeInfo jsonTypeInfo)
   at Elastic.Clients.Elasticsearch.Serialization.SystemTextJsonSerializer.Deserialize[T](Stream stream) in /_/src/Elastic.Clients.Elasticsearch/Serialization/SystemTextJsonSerializer.cs:line 65
   at Program.<Main>$(String[] args)

Code to reproduce:

        var c = new CreateIndexRequestDescriptor(conf.ElasticIndex);
        c.Mappings(m => {
            m.Properties(new Properties
            {
                { "_id", new LongNumberProperty(){ Index=false } },
                { "_access", new KeywordProperty() },
                { "_isactive", new BooleanProperty() },
                { "Type", new KeywordProperty() },
                { "Name", new TextProperty() },
                { "Description", new TextProperty() },
                { "CreateDate", new DateProperty() { Format = "yyyy-MM-dd HH:mm:ss.SSS" } },
                { "UpdateDate", new DateProperty() { Format = "yyyy-MM-dd HH:mm:ss.SSS" } }
            });
        });
        var json = elastic.RequestResponseSerializer.SerializeToString(c);
        elastic.RequestResponseSerializer.Deserialize<CreateIndexRequestDescriptor>(
                new MemoryStream(Encoding.UTF8.GetBytes(json))
            );

json contains correct mapping definition:

{
	"mappings":{
		"properties":{
			"_id":{"index":false,"type":"long"},
			"_access":{"type":"keyword"},
			"_isactive":{"type":"boolean"},
			"Type":{"type":"keyword"},
			"Name":{"type":"text"},
			"Description":{"type":"text"},
			"CreateDate":{"format":"yyyy-MM-dd HH:mm:ss.SSS","type":"date"},
			"UpdateDate":{"format":"yyyy-MM-dd HH:mm:ss.SSS","type":"date"}
		}
	}
}

However the last line throws exception i mentioned above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    8.xRelates to a 8.x client version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions