Unable to serialize double value
See original GitHub issueElastic.Clients.Elasticsearch version: 8.1.1
Elasticsearch version: 8.7.1
.NET runtime version: .NET FW 4.7.2
Operating system version: Win10 22H2
Description of the problem including expected versus actual behavior:
Cannot index an instance of a class containing a public property of type double.
Elastic.Transport.UnexpectedTransportException: Unable to serialize double value.
Steps to reproduce:
- Execute following code/unit test:
using System;
using System.Diagnostics;
using Elastic.Clients.Elasticsearch;
using Elastic.Transport;
using Xunit;
namespace SearchESSequenceResearch.V1
{
public class MyDecimalClass
{
public decimal MyDecimal { get; set; }
}
public class MyDoubleClass
{
public double MyDouble { get; set; }
}
public class TestIndexDouble
{
private const string TestMachineUriString = "https://docker.mydomain.com:9280"; // ES 8 in docker
private readonly Uri _testMachineUri = new Uri(TestMachineUriString);
[Fact]
public void TestIndexingDouble()
{
ElasticsearchClient client = GetClient();
var decimalInstance = new MyDecimalClass
{
MyDecimal = 123.45m
};
try
{
client.Index(decimalInstance, "mytestindex");
}
catch (Exception e)
{
Debug.WriteLine(e);
throw;
}
var doubleInstance = new MyDoubleClass
{
MyDouble = 123.45d
};
try
{
client.Index(doubleInstance, "mytestindex");
}
catch (Exception e)
{
Debug.WriteLine(e);
throw;
}
}
private ElasticsearchClient GetClient()
{
var settings = new ElasticsearchClientSettings(_testMachineUri)
.Authentication(new BasicAuthentication("elastic", "passwordhere"))
.ServerCertificateValidationCallback((o, cert, chain, errors) => true);
settings.DisableDirectStreaming();
var client = new ElasticsearchClient(settings);
return client;
}
}
}```
**Expected behavior**
The item should be serialized and addet to the index.
**Provide `DebugInformation` (if relevant)**:
Elastic.Transport.UnexpectedTransportException: Unable to serialize double value.
Elastic.Transport.UnexpectedTransportException
Unable to serialize double value.
bei Elastic.Transport.DefaultHttpTransport`1.ThrowUnexpectedTransportException[TResponse](Exception killerException, List`1 seenExceptions, RequestData requestData, TResponse response, RequestPipeline pipeline) in /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DefaultHttpTransport.cs:Zeile 328.
bei Elastic.Transport.DefaultHttpTransport`1.Request[TResponse](HttpMethod method, String path, PostData data, RequestParameters requestParameters) in /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DefaultHttpTransport.cs:Zeile 176.
bei Elastic.Clients.Elasticsearch.ElasticsearchClient.DoRequest[TRequest,TResponse,TRequestParameters](TRequest request, Action`1 forceConfiguration) in /_/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs:Zeile 217.
Issue Analytics
- State:
- Created 3 months ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Jackson fails to serialize a null Double - java
I am trying to serialize an object into an array and Jackson fails to do so with NPE. I am expecting something like...
Read more >Serialize a Nullable double property - best way
Hello! private double? _Width; [XmlAttribute("width")] public double? Width { get { return _Width; } set { if (value != null) _Width = Math....
Read more >Parsing Double in Mono (C#) fails
I need to serialize and dictionary or an object where some properties are double numbers, but I dont know how to fix this...
Read more >Efficient JSON serialization with Jackson and Java
JSON provides for a very restricted set of possible value types. ... Number is essentially Java's double with some corner cases.
Read more >Graphql custom query error: Can't convert '9' to double - Help
If I create a document through GraphQL and type in a value like 9 into the query, it gets serialized correctly as a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I submitted a PR for this last week, #7753. It is a bug that only happens when running .NET Framework, not .NET Core or later.
As a temporary workaround you can remove
DoubleWithFractionalPortionConverter
andFloatWithFractionalPortionConverter
from the serializer converters list when constructing the client.Yeah looking at this another minute shows that the .NET Framework code is completely broken (or rather, incomplete). Since there were not tests to verify it I missunderstood how severe this was. It didn’t just fall through to always throw an exception, the .NET Framework code copies the value into a
Span<byte>
, but it never writes it to theUtf8JsonWriter
.I can have a look at fixing this in the coming days and when #7769 is done we can add proper tests for this as well.