Skip to content

IAtsConvertable -- Allows custom De/Serialization across ATS boundaries#17473

Draft
cdbrown2018 wants to merge 4 commits into
microsoft:mainfrom
cdbrown2018:cdbrown2018/ats-convertable
Draft

IAtsConvertable -- Allows custom De/Serialization across ATS boundaries#17473
cdbrown2018 wants to merge 4 commits into
microsoft:mainfrom
cdbrown2018:cdbrown2018/ats-convertable

Conversation

@cdbrown2018
Copy link
Copy Markdown

Description

Adds support for declaring custom Serialization and Deserialization logic across ATS boundaries.

Two types have been added -- IAtsConvertable and CustomAtsObjectDto.

IAtsConvertable

Implement this interface to provide custom de/serialization logic for a type that is exported over ATS. The Deserialize and Serialize methods are marked static as it is expected these methods will return an object of the type these methods are defined on. IAtsConvertable was added to the Unmarshalling logic, so anything that implements the interface will be deserialized accordingly.

CustomAtsObjectDto

This class provides a default implementation of the IAtsConvertable. It simply takes a JsonObject and deserializes it to a Dictionary<string, object?>. The property is set to the class's Object property, to be used in SDK code. This allows completely custom objects to be sent across ATS boundaries, allowing client-code to specify their own objects. Particularly, this enables writing custom manifests for publishers, without having to make use of extension methods, and using the AppHost language's native object creation semantics.

An example of how this type is used is available in the #17074 PR.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Copilot AI review requested due to automatic review settings May 25, 2026 17:57
@cdbrown2018 cdbrown2018 requested a review from sebastienros as a code owner May 25, 2026 17:57
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17473

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17473"

@cdbrown2018 cdbrown2018 changed the title Cdbrown2018/ats convertable IAtsConvertable -- Allows custom De/Serialization across ATS boundaries May 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for custom ATS conversion for “generic” objects by introducing an IAtsConvertable contract and wiring AtsMarshaller to call custom Deserialize logic, with a new test validating deserialization into a dictionary-backed DTO.

Changes:

  • Introduce IAtsConvertable and CustomAtsObjectDto to support custom JSON ↔ object conversion across ATS boundaries.
  • Update AtsMarshaller to detect ATS-convertible types and invoke their custom deserializer.
  • Replace an existing unmarshalling test with a new test for custom ATS object DTO deserialization.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
tests/Aspire.Hosting.RemoteHost.Tests/AtsMarshallerTests.cs Adds test coverage for unmarshalling into CustomAtsObjectDto (but removes a prior init-list test).
src/Aspire.Hosting/Ats/AtsConvertable.cs Introduces IAtsConvertable and CustomAtsObjectDto with dictionary-based JSON conversion logic.
src/Aspire.Hosting.RemoteHost/Ats/AtsMarshaller.cs Adds detection and reflection-based invocation of Deserialize for ATS-convertible types.

Comment on lines +659 to +662
if (IsIAtsConvertable(targetType))
{
return targetType.GetMethod("Deserialize")?.Invoke(null, [jsonObj]);
}
Comment on lines +121 to +124
public static JsonNode? Serialize(object value)
{
return JsonSerializer.Serialize(value);
}
Comment on lines +12 to +13
public interface IAtsConvertable
{
/// Contains the result of deserialization.
/// </summary>
[AspireExportIgnore]
internal Dictionary<string, object?>? Object { get; set; }
Comment on lines +685 to +688
private static bool IsIAtsConvertable(Type type)
{
return type.GetInterfaces().Any(x => x.FullName == "Aspire.Hosting.Ats.IAtsConvertable");
}
Comment on lines +717 to +718
[Fact]
public void UnmarshalFromJson_UnmarshalsCustomAtsObjectDto()
@cdbrown2018 cdbrown2018 marked this pull request as draft May 25, 2026 19:08
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.

2 participants