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 for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube