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

  • Microsoft Revamps Fledgling AutoGen Framework for Agentic AI

    Only at v0.4, Microsoft's AutoGen framework for agentic AI -- the hottest new trend in AI development -- has already undergone a complete revamp, going to an asynchronous, event-driven architecture.

  • IDE Irony: Coding Errors Cause 'Critical' Vulnerability in Visual Studio

    In a larger-than-normal Patch Tuesday, Microsoft warned of a "critical" vulnerability in Visual Studio that should be fixed immediately if automatic patching isn't enabled, ironically caused by coding errors.

  • Building Blazor Applications

    A trio of Blazor experts will conduct a full-day workshop for devs to learn everything about the tech a a March developer conference in Las Vegas keynoted by Microsoft execs and featuring many Microsoft devs.

  • Gradient Boosting Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the gradient boosting regression technique, where the goal is to predict a single numeric value. Compared to existing library implementations of gradient boosting regression, a from-scratch implementation allows much easier customization and integration with other .NET systems.

  • Microsoft Execs to Tackle AI and Cloud in Dev Conference Keynotes

    AI unsurprisingly is all over keynotes that Microsoft execs will helm to kick off the Visual Studio Live! developer conference in Las Vegas, March 10-14, which the company described as "a must-attend event."

Subscribe on YouTube