AnointedAutomation.Objects.API 1.3.2

dotnet add package AnointedAutomation.Objects.API --version 1.3.2
                    
NuGet\Install-Package AnointedAutomation.Objects.API -Version 1.3.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AnointedAutomation.Objects.API" Version="1.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AnointedAutomation.Objects.API" Version="1.3.2" />
                    
Directory.Packages.props
<PackageReference Include="AnointedAutomation.Objects.API" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AnointedAutomation.Objects.API --version 1.3.2
                    
#r "nuget: AnointedAutomation.Objects.API, 1.3.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AnointedAutomation.Objects.API@1.3.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AnointedAutomation.Objects.API&version=1.3.2
                    
Install as a Cake Addin
#tool nuget:?package=AnointedAutomation.Objects.API&version=1.3.2
                    
Install as a Cake Tool

AnointedAutomation.Objects.API

Jesus is King ✝️

ASP.NET Core companions to AnointedAutomation.Objects: an in memory IFormFile, the shared hybrid casing System.Text.Json convention used by AnointedAutomation APIs, and a never throwing GraphQL response reader.

NuGet Downloads

Installation

dotnet add package AnointedAutomation.Objects.API
  • Target framework: net10.0
  • Framework reference: Microsoft.AspNetCore.App (ASP.NET Core shared framework)
  • Dependencies:

Quick start

Apply the JSON casing convention to both MVC controllers and minimal APIs:

using AnointedAutomation.Objects.API;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers()
    .AddJsonOptions(o => JsonCasingConvention.Configure(o.JsonSerializerOptions));
builder.Services.ConfigureHttpJsonOptions(o => JsonCasingConvention.Configure(o.SerializerOptions));

WebApplication app = builder.Build();
app.MapControllers();
app.Run();

API overview

All types are in the AnointedAutomation.Objects.API namespace.

Type Description
JsonCasingConvention static void Configure(JsonSerializerOptions options) adds the convention to existing options; static JsonSerializerOptions Options is a ready made, reusable instance for serializing outside the MVC/minimal API pipeline.
UtcDateTimeJsonConverter JsonConverter<DateTime> registered by JsonCasingConvention.Configure. Writes every DateTime as UTC ending in Z (Unspecified is treated as UTC, Local is converted); reading is unchanged. static DateTime ToUtc(DateTime value) applies the same rule.
CustomFormFile IFormFile backed by a byte[]. Constructor (string fileName, byte[] content); properties FileName, Content, Length, ContentType (always application/octet-stream), Name (always file), ContentDisposition, Headers; methods CopyTo, CopyToAsync, OpenReadStream.
GraphQlEnvelope static GraphQlResult Read(string body) parses a GraphQL HTTP response body. Never throws: empty or invalid bodies become transport errors.
GraphQlResult Data (JsonElement), HasData, TransportErrors, Errors, and per mutation helpers Payload(field), UserErrors(field), FirstError(field), Succeeded(field).
GraphQlError One top level error: Message, plus raw JSON Path and Extensions (or null).

JSON casing rules

JsonCasingConvention makes the wire casing match the AnointedAutomation model convention while your C# stays PascalCase:

  • Classes: value type members (int, bool, DateTime, enums, and their nullables) are camelCase; reference type members (strings, objects, arrays) are PascalCase.
  • Structs: every member is camelCase.
  • Enums serialize as camelCase strings (integers are still accepted on input).
  • A member with [JsonPropertyName] keeps its explicit name, and anonymous types are left untouched.
  • Every DateTime is written as UTC ending in Z, so browsers never read it as local time. A value with Kind Unspecified is treated as UTC and a Local one is converted. Reading keeps the default parsing.
using System.Text.Json;
using AnointedAutomation.Objects.API;

string json = JsonSerializer.Serialize(
    new OrderDto { Id = 7, Name = "Hoodie", TotalPrice = 49.99m },
    JsonCasingConvention.Options);
// {"id":7,"Name":"Hoodie","totalPrice":49.99}

public class OrderDto
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal TotalPrice { get; set; }
}

The same rule is applied to MongoDB documents by HybridElementNameConvention in AnointedAutomation.Repository.Mongo.

Reading GraphQL responses

using AnointedAutomation.Objects.API;

string body = "{\"data\":{\"productUpdate\":{\"userErrors\":[{\"message\":\"Title can't be blank\"}]}}}";

GraphQlResult result = GraphQlEnvelope.Read(body);
if (!result.Succeeded("productUpdate"))
{
    string error = result.FirstError("productUpdate"); // "Title can't be blank"
}

FirstError returns the first top level error if any, otherwise the first data.{field}.userErrors[].message, otherwise null. The shape matches the Shopify Admin GraphQL API, but nothing here is Shopify specific.

Building a form file in memory

using System.IO;
using System.Threading.Tasks;
using AnointedAutomation.Objects.API;
using Microsoft.AspNetCore.Http;

public static class Uploads
{
    public static async Task<long> SaveAsync(byte[] bytes, string path)
    {
        IFormFile file = new CustomFormFile("report.pdf", bytes);
        using FileStream stream = File.Create(path);
        await file.CopyToAsync(stream);
        return file.Length;
    }
}

Useful for tests, or for passing generated content to code that expects an IFormFile.

License

MIT. See LICENSE.

Support This Project

This library is free and open source. The best way to support the work is to shop with us:

Found a bug or have a request? Open an issue at https://github.com/AnointedAutomation/AnointedAutomation/issues.

Moved to AnointedAutomation.Serialization (1.3.0)

JsonCasingConvention and UtcDateTimeJsonConverter now live in AnointedAutomation.Serialization.SystemTextJson. The types in this package are thin delegating shims kept so existing code compiles unchanged; prefer the Serialization types (and AnointedJson.ConfigureApi) in new code.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.2 72 10/26/2026
1.3.1 455 10/1/2026
1.3.0 134 10/1/2026
1.2.0 149 9/27/2026
1.1.2 182 9/25/2026
1.1.1 409 8/23/2026
1.1.0 136 8/18/2026
1.0.3 548 6/27/2026
1.0.2 582 5/30/2026
1.0.1 634 3/15/2026
1.0.0 178 3/15/2026
0.0.18 245 3/11/2026
0.0.17 382 3/1/2026
0.0.16 148 3/1/2026
0.0.15 172 2/26/2026
0.0.14 197 2/21/2026
0.0.13 156 2/21/2026
0.0.12 139 2/21/2026
0.0.11 154 2/20/2026
0.0.10 210 2/20/2026
Loading failed