Skip to content

Cosmos: Allow to use a custom JSON serializer #17306

Closed

Description

@AndriySvyryd

Allow value converters to output a raw object (e.g. JToken)

Also provide access to unmapped properties (through a JSON shadow property or dynamic property bag).

Make sure that FromSqlRaw parameters are properly serialized.

Test with STJ source generators

Related to #14570, #30677

Activity

  1. changed the title [-]Cosmos: Allow to plugin a custom JSON serializer[/-] [+]Cosmos: Allow to use a custom JSON serializer[/+] on Aug 21, 2019
  2. added this to the Backlog milestone on Aug 26, 2019
  3. ajcvickers commented on May 6, 2021

    @ajcvickers
    Contributor

    Note from triage: this is currently blocked on the new Cosmos SDK, tracked by #18753.

  4. modified the milestones: Backlog, 7.0.0 on Oct 27, 2021
  5. bjorn-ali-goransson commented on Nov 20, 2021

    @bjorn-ali-goransson

    Yes please! This way I will be able to serialize an IList<ISomeCustomInterface> - there and back again ...

  6. vyarymovych commented on Jan 20, 2022

    @vyarymovych
  7. roji commented on Jan 20, 2022

    @roji
  8. vyarymovych commented on Jan 20, 2022

    @vyarymovych
  9. roji commented on Jan 20, 2022

    @roji
  10. 14 remaining items

  11. roji commented on Jan 22, 2024

    @roji
    Member

    There are tons of benchmarks out there.

    My comment above was whether the performance difference here would be actually meaninful when working with Cosmos specifically, given that you're transferring data over the network to a cloud service that's performing I/O to search and execute queries. I'd recommend avoiding assumptions about perf without actually checking.

  12. klemmchr commented on Jan 22, 2024

    @klemmchr

    You're confusing latency with resource utilization. I'm explicitly talking about CPU and RAM usage and not about latency issues (that are common for all cloud services). I'm not making assumptions, I'm citing benchmarks done by Microsoft. There are tons of other benchmarks out there too. I don't see where this is going given that you're just ignoring the reason why Newtonsoft is bad as a hardcoded serializer.

    I just don't get this argument. You're basically saying that all other performance factors are completely irrelevant once I/O and network is involved. This would mean that we don't need any more performance improvements for ASP.NET or Microsoft.Data.SqlClient. This is just weird to argue about.

  13. roji commented on Jan 22, 2024

    @roji
    Member

    @klemmchr I did not mention latency vs. resource utilization - the question is whether the resource utilization you're referring to, e.g. the extra allocations, are meaningful to the overall performance specifically when interacting with Cosmos.

    In other words, you may very well find out that switching from Newtonsoft.Json to System.Text.Json considerably reduces memory allocations, but does nothing to your general application performance, since that improvement is negligible compared to everything else that has to happen to service a Cosmos request. If that's the case, then spending time on this feature for performance reasons isn't worth it (it may be worth it for other reasons, e.g. functionality differences between the two serializers).

    I just don't get this argument. You're basically saying that all other performance factors are completely irrelevant once I/O and network is involved. This would mean that we don't need any more performance improvements for ASP.NET or Microsoft.Data.SqlClient.

    I'm not. It's good to be concerned with performance, but it's important to always have a holistic view of performance when optimizing things - especially when considering priority (i.e. where we invest our time). If reducing a few allocations in a path where those are negligible doesn't actually get you anything, then that's not something we should prioritize. Otherwise we can spend a lot of time on meaningless micro-optimizations which technically improve performance, but not in any way that matters to anyone. I hope that's clear.

    To summarize, I think this is something we should do in general, but I'd be surprised if it would lead to a meaningful improvement perf-wise when working with Cosmos. I'd be happy to see actual figures to the contrary though.

  14. added theissue type on Jun 15, 2025
  15. AndriySvyryd commented on Jul 15, 2026

    @AndriySvyryd
    MemberAuthor

    This was mostly implemented in #38024 and #38550
    The remaining parts are tracked in #14570 and #20584

  16. modified the milestones: Backlog, 11.0.0 on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions