question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom serializer breaks query

See original GitHub issue

We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.

Describe the bug The options exposed for the built-in serializer are limited only to changing the name. Additional changes requires a custom serializer. However, any modifications in the custom serializer are not used when performing a query, making the option mostly useless.

To Reproduce

Example data:

enum CustomerRole {
  Customer,
  Manager
}
record Customer(string Id, string Name, CustomerRole Role);

var results = (await _container.GetItemLinqQueryable<Customer>().Where(x => x.Role == CustomerRole.Customer)).ToList();

Generated document (with custom serializer):

{
  "name": "John Doe"
  "role": "Customer",
  "id": "..."
}

Expected behavior The generated SQL should follow the settings on the custom serializer, i.e.: WHERE c.role == "Customer"

The results variable should contain the customer element.

Actual behavior The generated SQL follows the default serializer and returns wrong name and value, i.e.: WHERE c.Role == 0

The results variable is always empty.

Environment summary SDK Version: 3.28 OS Version: any

Additional context An additional problem is that when setting a default serializer as in the example, it is not possible to also set the SerializerOptions, so all queries will fail unless each instantiated query also has specific serializer options set. This happens in the linked example as well, because the naming convention is changed.

This is similar to issues #3207 and #2685.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
ealsurcommented, Jan 5, 2023

@jackbond Should be included in the next release, yes.

1reaction
jackbondcommented, Aug 9, 2023

At this point, I’m beginning to wonder if anyone other than Scott Guthrie can ensure this bug is resolved. Seriously, what is it going to take??? It’s 2023, System.Text.Json has been out FOR YEARS, and the Cosmos team continues to whistle past graveyards and simply acts like there isn’t a problem. Here’s an idea, publish a completely separate NuGet package that replaces every usage of Newtonsoft with STJ. We don’t need custom serializer support, NOBODY DOES. We need System.Text.Json support and we needed it YEARS AGO!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom JSON representation of query result - django
One way to do this is by overriding the to_representation method in serializers.ListSerializer . class CustomListSerializer(serializers.
Read more >
Calling Default Serializer from Custom Serializer in Jackson
In this short tutorial, we'll take a look at custom Jackson serializers and show how to access default serializers inside a custom serializer....
Read more >
Jackson - Custom Serializer
Control your JSON output with Jackson 2 by using a Custom Serializer. ... Repeatedly, code that works in dev breaks down in production....
Read more >
Custom Serialization | Elasticsearch .NET Clients [7.17]
A custom serializer would not know how to serialize QueryContainer or other NEST types that could appear as part of the _source of...
Read more >
Custom Serialization | Elasticsearch.Net and NEST
A custom serializer would not know how to serialize QueryContainer or other NEST types that could appear as part of the _source of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found