Quantcast
Channel: Mobile - Couchbase Forums
Viewing all articles
Browse latest Browse all 1117

Some properties in my document was read like float instead of integer

$
0
0

Hello,

I migrate my CouchBaseLite from 2.7 to 2.8 et Async Gateway to version 3.0.

my problem is : some properties of a document are interpreted as float instead of integer.
I have lot of types of documents but it’s just with one there is a problem.

when i read data from Couchbase Lite, the dictionary returned by the querybuilder indicates that my property is of type float and not integer. the value is however in integer format.

Below is the code that reads the data in couchBaseLite and turns the document into a .NET class.
The JSON serialization writes the properties in decimal format and the deserialization in my class crashes because I expect integers and not floats

    public IEnumerable<T> Query(IExpression expression)
    {
        List<T> convertedResult = new List<T>();

        using (var query = QueryBuilder.Select(SelectResult.All())
                        .From(DataSource.Database(_data.Db))
                        .Where(Expression.Property("type").EqualTo(Expression.String(_documentType))
                        .And(Expression.Property("isDeleted").IsNot(Expression.Boolean(true)))
                        .And(expression)))
        {
            foreach (var result in query.Execute())
            {
                var dict = result.GetDictionary(_data.Db.Name);
                var data = dict.ToDictionary();
                var json = JsonConvert.SerializeObject(data, _settings);

                var value = JsonConvert.DeserializeObject<T>(json, _settings);
                convertedResult.Add(value));
            }
        }

        return convertedResult;
    }

thanks for you help

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1117

Trending Articles