agentleFS
LeanMeanCleanAppsLeanMeanCleanApps/CleanLambdaFunction/.agents/skills/json-serialization/SKILL.md

json-serialization

Skill0 starsChanged 10 days agoMITView on GitHub

How this Lambda function reads and writes JSON - the assembly-level LambdaFunctionJsonSerializer with camelCase names, the source-generated LambdaFunctionJsonSerializerContext, which types it must list, and how JSON is shaped. Use when adding a request or response type, changing how JSON looks, or when a value serialises differently than expected.

4 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add every new request and response type to LambdaFunctionJsonSerializerContext with [JsonSerializable(typeof(...))], including each Page<T> …

    line 25
  2. Distinctive:

    Add a serializer test for a new request type (it reads the JSON a caller sends) and for any response whose shape matters to callers.

    line 27
  3. Very specific:

    Use [JsonPropertyName] to rename one property.

    line 46
  4. Very specific:

    Use Newtonsoft.Json or Amazon.Lambda.Serialization.Json.

    line 47

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

JSON serialization (Lambda function)

The rule

Lambda hands the function a JSON payload and expects JSON back. The [assembly: LambdaSerializer(...)] attribute at the top of LambdaFunction.cs sets the serializer for every function: LambdaFunctionJsonSerializer in src/Presentation/LambdaFunction/Serialization/. It's a SourceGeneratorLambdaJsonSerializer<LambdaFunctionJsonSerializerContext> from Amazon.Lambda.Serialization.SystemTextJson that writes camelCase, like the other templates. It uses the source-generated metadata in src/Presentation/LambdaFunction/Serialization/LambdaFunctionJsonSerializerContext.cs, so nothing is serialised with reflection, which keeps cold starts short.

BehaviourEffect
Property names read in any case{"query":"star"} and {"Query":"star"} both fill Query
Property names written in camelCaseResponses read items, totalCount, nextOffset
Nulls left outNextOffset disappears on the last page, AverageStars when there are no reviews
Only listed typesA type missing from the context can't be serialised

Responses are trees: a list returns flat records, and a review holds a flat Movie and a flat Author. There's no cycle handling.

Steps

  1. Add every new request and response type to LambdaFunctionJsonSerializerContext with [JsonSerializable(typeof(...))], including each Page<T> you return. The HTTP API functions also need Problem, APIGatewayHttpApiV2ProxyRequest and APIGatewayHttpApiV2ProxyResponse, which are already there.
  2. Change how JSON looks in the LambdaFunctionJsonSerializer constructor, not on single properties, and keep the request and response tests in tests/Presentation.Tests.Unit/Serialization/LambdaFunctionJsonSerializerTests.cs in step. The serializer's own options replace the context's, so [JsonSourceGenerationOptions] on the context has no effect.
  3. Add a serializer test for a new request type (it reads the JSON a caller sends) and for any response whose shape matters to callers.

Example

// src/Presentation/LambdaFunction/Serialization/LambdaFunctionJsonSerializerContext.cs
[JsonSerializable(typeof(ListRequest))]
[JsonSerializable(typeof(ListReviewsRequest))]
[JsonSerializable(typeof(Page<Movie>))]
[JsonSerializable(typeof(Page<Author>))]
[JsonSerializable(typeof(Page<Review>))]
public partial class LambdaFunctionJsonSerializerContext : JsonSerializerContext
{
}

Don't

  • Switch to DefaultLambdaJsonSerializer or CamelCaseLambdaJsonSerializer. They use reflection and slow every cold start.
  • Use [JsonPropertyName] to rename one property.
  • Use Newtonsoft.Json or Amazon.Lambda.Serialization.Json.
  • Let a response type refer back to its parent.

Check

dotnet test tests/Presentation.Tests.Unit --filter "FullyQualifiedName~Serializer"

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.