Objects not being deserialized from Query
See original GitHub issueDescribe the bug When returning a collection from a query, the items in the collection are default/unpopulated objects.
To Reproduce
public async Task<IEnumerable<Person>> SearchPersons(string search)
{
QueryDefinition qd = await PersonSearchQueryDefinitionParser.BuildSearchQuery(search);
List<Person> ret = new List<Person>();
FeedIterator<Person> feed = Container.GetItemQueryIterator<Person>(qd);
while (feed.HasMoreResults)
{
var curr = await feed.ReadNextAsync();
ret.AddRange(curr);
}
return ret;
}
ret has the expected number of objects in its collection, but they are default. The custom CosmosSerializer is called only once for PartitionedQueryExecutionInfo, but not for either of the returned objects.
Serializer:
public class StorageSerializer : CosmosSerializer
{
private static readonly JsonSerializer Serializer = JsonSerializer.Create(new JsonSerializerSettings {
Converters = new List<JsonConverter>() { new ContactConverter() },
ContractResolver = new StorageContractResolver()
});
private static readonly Encoding DefaultEncoding = new UTF8Encoding(false, true);
public override T FromStream<T>(Stream stream)
{
using (stream)
{
if (typeof(Stream).IsAssignableFrom(typeof(T)))
{
return (T)(object)(stream);
}
using (StreamReader sr = new StreamReader(stream))
using (JsonTextReader r = new JsonTextReader(sr))
{
return Serializer.Deserialize<T>(r);
}
}
}
public override Stream ToStream<T>(T input)
{
MemoryStream ret = new MemoryStream();
using (StreamWriter sw = new StreamWriter(ret, encoding: DefaultEncoding, bufferSize: 1024, leaveOpen: true))
using (JsonTextWriter jw = new JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;
Serializer.Serialize(jw, input);
jw.Flush();
sw.Flush();
}
ret.Position = 0;
return ret;
}
}
Expected behavior ret should be populated with two deserialized objects.
Actual behavior It appears that deserialization doesn’t happen. Because the Serializer being used is custom and based on Json.NET, the objects aren’t decorated with non-Json.NET attributes.
When debugging, curr.CosmosElements is populated with two objects. The custom CosmosSerializer is not called for the two elements.
Environment summary SDK Version: Microsoft.Azure.Cosmos v3.0.0 OS Version (e.g. Windows, Linux, MacOSX): Windows 10
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
I can probably come up with something tomorrow.
D
On Tue, 30 Jul 2019 at 19:43, j82w notifications@github.com wrote:
@j82w