Thursday, October 29, 2020

JsonSrcGen 1.0.0.1 RC 1 Released

JsonSrcGen 1.0.0.1 RC 1 Released

JsonSrcGen 1.0.0.1 RC 1 has been released, This is the first release candidate leading up to the first production ready release. JsonSrcGen is now feature complete.

Changes

  • Serialises from ReadOnlySpan<char> instead of from string

New Features

  • Support skipping null values when serialising
  • Support DateTimeOffset

Serialises from ReadOnlySpan<char> instead of from string

From Json conversions now serialize from ReadOnlySpan<char> instead of string. Strings can be converted to ReadOnlySpan<char> very cheaply but converting a ReadOnlySpan<char> to a string is expensive because it requires allocating memory. c# will automatically convert string to ReadOnlySpan<char> so you can continue to use strings.

Support skipping null values when serialising

The attribute [JsonIgnoreNull] can be added to a class to instruct JsonSrcGen to skip serializing null values. 

Real Json Testing program

If you would like to ensure your Json API works with JsonSrcGen then you can submit your tests to be included in our RealJsonTests folder via a merge request. The JsonSrcGen developers will ensure that any tests included here pass for each new release.

Tests must meet the following criteria:
  • Use nunit
  • Use local json data (no external API calls from the tests)
API's are eligible for free inclusion under any of the following conditions:
  • The API is available to the public free of charge.
  • The server or client code is available under an OSI approved opensource licence.
If your API does not meet the above conditions please contacts the maintainers to discus how you can support the development in exchange for having your tests included.

Call to testing

Please test JsonSrcGen against your Json and raise bug reports for any problem you find.

Please checkout the JsonSrcGen project on github: https://github.com/trampster/JsonSrcGen

JsonSrcGen is available as a nuget package:

Friday, October 9, 2020

JsonSrcGen 0.2.0 Alpha Released

JsonSrcGen 0.2.0 Alpha Released

JsonSrcGen 0.2.0 alpha has been published. This release contains the following changes:

Breaking Changes
  • Serialise to ReadOnlySpan<char> instead of string
  • JsonSrcGenConvert renamed to JsonConverter
New Features
  • Support for Json Values
  • Support for Custom Converters
  • Support for char

Serialise to ReadOnlySpan<char> instead of string

To Json conversions now produce ReadOnlySpan<char> instead of string, is produces a significant speedup as it allows us to avoid the memory allocation required to create the String. The ReadOnlySpan reuses the same memory for each ToJson conversion within a thread. Because of this the ReadOnlySpan must be consumed before calling ToJson again or the data it points at will change.


Support for Json Values

Simple Json Values can not be convertered to and from Json. To do this you must specify a JsonValue attribute at the solution level as follows:


[assembly: JsonValue(typeof(int))]

...

var converter = new JsonConverter

ReadOnlySpan<char> json = converter.ToJson(1456);

int value = converter.FromJson(0, "1456"); 

Support for Custom Converters

Custom Converters allow you to provide a custom conversion code for a type. To do so you must implement ICustomConverter<T> and add the CustomConverter attribute to your class.


[CustomConverter(typeof(int))]
public class CustomCaseStringConverter : ICustomConverter<int>
{
    public void ToJson(IJsonBuilder builder, int value)
    {
        // Write your json to the builder here
    }

    public ReadOnlySpan<char> FromJson(ReadOnlySpan<char> json, ref int value)
    {
        // Read the Json from the json span here
    }
}

Please checkout the JsonSrcGen project on github: https://github.com/trampster/JsonSrcGen

JsonSrcGen is available as a nuget package: