News

.NET 7 Preview 6 Adds JSON Contract Customization

The sixth preview of .NET 7 improves type converter functionality, updates System.Formats.Tar APIs, adds constraints to .NET template authoring, boosts CodeGen performance and allows for JSON contract customization.

The latter enhancement gives developers more control over what and how types get serialized or deserialized when working with JSON contracts.

"In certain situations developers serializing or deserializing JSON find that they don't want to or cannot change types because they either come from external library or it would greatly pollute the code but need to make some changes which influence serialization like removing property, changing how numbers get serialized, how object is created etc," said Microsoft's Jon Douglas, senior program manager, NuGet, in a July 12 announcement. "They frequently are forced to either write wrappers or custom converters which are not only a hassle but also make serialization slower."

Douglas explained how to opt in to customization, different types of customizations, how properties are customized and conditional serialization of properties. He also provided a code sample to detail how to ignore properties with a specific name or type.

Themes of .NET for v7 Milestone
[Click on image for larger view.] Themes of .NET for v7 Milestone (source: Microsoft).

In addition to JSON contract customization, following are capsule summarizations of some other Preview 6 highlights, following general guidance on the Themes of .NET site (pictured above):

  • Type converters: The team provided type converters for new primitive types including DateOnly, TimeOnly, Int128, UInt128 and Half.
  • System.Formats.Tar API updates: The team tweaked the System.Formats.Tar assembly that was introduced in an earlier preview in order to provide APIs for manipulating TAR archives. Changes were made to cover some special cases involving:
    • Global Extended Attributes specialized class -- a new class was added to describe a GEA entry.
    • Entry format, not archive format -- The team discovered that entries of different formats can be intermixed in a single TAR archive, so the TarFormat enum was renamed to TarEntryFormat.
    • Writing and reading changes -- The Format property was removed from TarReader because no archive is expected to have all its entries in a single format.
  • Template authoring: This was improved in three ways:
    • Constraints -- Introduced in this preview for .NET Templates, constraints help developers define the context in which templates are allowed, helping the template engine determine which templates it should show in commands such as dotnet new list. Preview 6 supports three kinds of constraints:
      • Operating System constraints limit templates based on the OS of the user.
      • Template Engine Host constraints limit templates based on which host is executing the Template Engine, which is usually the .NET CLI itself, or embedded scenarios such as the New Project Dialog in Visual Studio/Visual Studio for Mac.
      • Installed Workloads constraints require that the specified .NET SDK workload is installed before the template will become available.
    • Multi-choice parameters -- When working with choice parameters, developers can now specify more than one value in a single selection, similar to the way a Flags-style enum might be used. Some potential common examples of this type of parameter include:
      • Opting into multiple forms of authentication on the web template
      • Choosing multiple target platforms (ios, android, web) at once in the maui templates
      More information on this is available here.
    • Exit codes unification and reporting -- This release unifies exit codes reported by the Template Engine, which is expected to help users who rely on scripting in shells to enjoy a more consistent error-handling experience. Also, errors reported by the .NET CLI now include a link so developers can find detailed information about each exit code.
  • CodeGen: Here, the dev team was helped out with a bunch of community PRs. Changes affected dynamic PGO (profile-guided optimization), Arm64, and loop optimizations, along with other more general optimizations.

Breaking changes, meanwhile, are listed here by area and release with links to detailed explanations, while proposed breaking changes that are still under review can be seen here.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Mastering Blazor Authentication and Authorization

    At the Visual Studio Live! @ Microsoft HQ developer conference set for August, Rockford Lhotka will explain the ins and outs of authentication across Blazor Server, WebAssembly, and .NET MAUI Hybrid apps, and show how to use identity and claims to customize application behavior through fine-grained authorization.

  • Linear Support Vector Regression from Scratch Using C# with Evolutionary Training

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the linear support vector regression (linear SVR) technique, where the goal is to predict a single numeric value. A linear SVR model uses an unusual error/loss function and cannot be trained using standard simple techniques, and so evolutionary optimization training is used.

  • Low-Code Report Says AI Will Enhance, Not Replace DIY Dev Tools

    Along with replacing software developers and possibly killing humanity, advanced AI is seen by many as a death knell for the do-it-yourself, low-code/no-code tooling industry, but a new report belies that notion.

  • Vibe Coding with Latest Visual Studio Preview

    Microsoft's latest Visual Studio preview facilitates "vibe coding," where developers mainly use GitHub Copilot AI to do all the programming in accordance with spoken or typed instructions.

  • Steve Sanderson Previews AI App Dev: Small Models, Agents and a Blazor Voice Assistant

    Blazor creator Steve Sanderson presented a keynote at the recent NDC London 2025 conference where he previewed the future of .NET application development with smaller AI models and autonomous agents, along with showcasing a new Blazor voice assistant project demonstrating cutting-edge functionality.

Subscribe on YouTube