Skip to content

Add OData header writing to ODataJsonOutputContext#3483

Open
Copilot wants to merge 2 commits intomainfrom
copilot/add-odata-headers-support
Open

Add OData header writing to ODataJsonOutputContext#3483
Copilot wants to merge 2 commits intomainfrom
copilot/add-odata-headers-support

Conversation

Copy link

Copilot AI commented Jan 16, 2026

The new ODataUtf8JsonWriter-based serializer writes payloads but not OData headers (OData-Version, Content-Type). This works when using ODataMessageWriter (which writes headers first), but fails when ODataJsonOutputContext is created directly (e.g., in URI conversion utilities).

Changes

ODataMessageInfo

  • Added optional internal Message property to carry message reference when header writing is needed

ODataMessageWriter

  • Passes message reference to ODataMessageInfo when creating output context

ODataJsonOutputContext

  • Writes OData-Version and Content-Type headers in constructor when message is available
  • BuildContentTypeHeader() assembles Content-Type from media type, parameters, and charset
  • Single-pass parameter iteration for charset detection
  • Only executes when message provided (zero overhead for internal usage)

Example

// Direct creation now writes headers
var messageInfo = new ODataMessageInfo
{
    Message = message,  // Optional - enables header writing
    MediaType = new ODataMediaType("application", "json"),
    // ...
};

var context = new ODataJsonOutputContext(messageInfo, settings);
// Headers automatically written: OData-Version: 4.0, Content-Type: application/json;charset=utf-8

Backward compatible - existing code paths unaffected.

Original prompt

This section details on the original issue you should resolve

<issue_title>New OData serializer does not write OData headers</issue_title>
<issue_description>

The OData serializer should write OData-specific headers based on the configuration it uses to write the request/response. For example: The OData version, the content-type, e.g:

OData-Version: 4.0
Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8

The ODataMessageWriter accepts a IODataRequest/ResponseMessage which wraps both the stream and the headers collection. It uses this wrapper to read and write headers when appropriate. The new serializer should provide a similar mechanism. But we should avoid unnecessary allocations, especially per-request allocations.


🔹 Thanks for taking the time to suggest this feature! We appreciate your contributions. 🙌
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add support for writing OData-specific headers Add OData header writing to ODataJsonOutputContext Jan 16, 2026
Copilot AI requested a review from odero January 16, 2026 09:51
Copilot AI and others added 2 commits February 6, 2026 04:21
- Add Message property to ODataMessageInfo to optionally carry message reference
- Update ODataMessageWriter to pass message to ODataMessageInfo
- Add WriteODataHeaders() method to ODataJsonOutputContext
- Headers (OData-Version, Content-Type) are now written when message is available
- Maintains backward compatibility - headers only written when message provided

Co-authored-by: odero <380686+odero@users.noreply.github.com>
- Combine charset check with parameter iteration (single pass)
- Add StringBuilder capacity hint to reduce allocations
- Make BuildContentTypeHeader static
- Add comments about parameter safety

Co-authored-by: odero <380686+odero@users.noreply.github.com>
@odero odero force-pushed the copilot/add-odata-headers-support branch from f51c4ce to 9ea1862 Compare February 6, 2026 12:21
@odero odero marked this pull request as ready for review February 6, 2026 12:22
@odero odero requested a review from habbes February 6, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New OData serializer does not write OData headers

2 participants