DEV Community

Al Rodriguez
Al Rodriguez

Posted on

New Project: C# Json Serializer Context Registrations Generator

This post was originally posted at my personal blog at: https://programmeral.com/posts/20241208_JsonSerializerContextRegistrationGenerator

New Project: C# Json Serializer Context Registrations Generator

Do you use the built-in System.Text.Json Source Generator to generate code to serialize/deserialize JSON objects without using reflection? If so, you know it can be a hassle to remember to register all of the classes with the code generator. I know I think it's a hassle, and easy to forget.

That's why I made this project to make the developer experience of registering those classes a little easier. Instead of adding them all above a single class, you can add a custom attribute above each class that should be registered, and then a .NET Tool will generate a class with all of the registrations in the single file for you. Then then built-in System.Text.Json Source Generator will run off that.

The full details are in the project README at: https://github.com/ProgrammerAL/json-serializer-context-registration-generator. It also includes instructions on how to setup your code to use this.

NuGet Packages

There are 2 NuGet packages. One for the attributes you add to your code, and the other for a .NET Tool to generate code files based on how the attributes were used.

The attributes are in package ProgrammerAL.JsonSerializerRegistrationGenerator.Attributes, and the .NET Tool is at ProgrammerAL.JsonSerializerRegistrationGenerator.Runner

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay