JsonRazor 2.0.1-rc

This is a prerelease version of JsonRazor.
There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonRazor --version 2.0.1-rc                
NuGet\Install-Package JsonRazor -Version 2.0.1-rc                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonRazor" Version="2.0.1-rc" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonRazor --version 2.0.1-rc                
#r "nuget: JsonRazor, 2.0.1-rc"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JsonRazor as a Cake Addin
#addin nuget:?package=JsonRazor&version=2.0.1-rc&prerelease

// Install JsonRazor as a Cake Tool
#tool nuget:?package=JsonRazor&version=2.0.1-rc&prerelease                

2.0.1-rc-2:

Changes to existing code:

  • Deserializer's Consume<T>(string, ModelMembers, bool) became Consume(Type, string), Consume<T>(StreamReader, ModelMembers, bool) became Consume(Type, StreamReader), and Consume<T>(JsonToken, ModelMembers, bool) became Consume(Type, JsonToken), and all of them return object now. Maybe non-generic methods are less fancy, but are unquestionably superior. They don't even call generic code. Members & useInfo parameters has been removed, so that all settings actuallt base on available static properties of Deserializer, so that most of call can use common configuration without being overriden by compile-constant default values. This is equivalent of constructing Deserialization via LikeDeserializer() method.
  • Serializer's Produce<T>(T, ModelMembers, bool) became Produce(object), Produce<T>(StreamWriter, T, ModelMembers, bool) became Write(StreamWriter, object), since it doesn't return anything. ProduceTokens<T>(T, ModelMembers, bool) became ProduceTokens(object), and WriteReadable<T>(StreamWriter, T, ModelMembers, bool) became WriteReadable(StreamWriter, object). Likewise, they behave like Serialization constructed via LikeSerializer() method.
  • Serialization's (currently only CachingSerializer is provided as implementation) FromType<T>(T) has been changed to FromType(object, Type). Existing overload FromType(object) will now become the default one, and it still infers type from passed instance. Output of FromType(object, Type) will be restricted to the type denoted by parameter (useful when source is devired type and we want to serialize it as its base class). FromType(StreamWriter, object, Type) overload has been added to FromType(StreamWriter, object), and it works in analogous way. TokensFromType<T>(T) has been changed to TokensFromType(object), and TokensFromType(object, Type) has been added. Not sure why they were missing.
  • JsonToken.From<T>(T) became From(object) and ConvertSelf<T>(ModelMembers, bool) became ConvertSelf<T>().
  • IToken.Convert<T>(ModelMembers, bool) became Convert<T>().
  • Serializer.OmitNullTokens has been renamed to OmitNulls, since this flag controls all Produce / Write / ProduceTokens / WriteReadable output, not only tokens.
  • Deserializers should no longer throw exception if found property has no defined setter, it'll just be ignored.
  • Serializer / CachingSerializer and tokens move from using format "s" for DateTime to "yyyy-MM-ddTHH:mm:ss.fffffffZ".
  • Serializer / CachingSerializer no longer serializes DateTimeOffset, TimeSpan, Guid, Uri, Regex (and in case of framework version above .NET 3.5, BigInteger) as objects, they'll be serialized just like one may expect. In case of DateTimeOffset, "yyyy-MM-ddTHH:mm:ss.fffffffzzz" format is used. These types should still be deserialized from previous representation, so it's backward compatible (but I doubt Regex would even work back then, smh). Under .NET 3.5 Guid parser uses custom code, so cannot guarantee that formats other than default xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx will work tho.

New features:

  • Serializer.SetPrimitiveConversion(Type, Func<object, string>, Func<string, object>) has been added. Allows to register own conversions for classes, like custom implementation of BigDecimal, so that instance may be written in readable, concise way without exposing internals. Type conversions added by default (for DateTimeOffset, TimeSpan, Guid, Uri, Regex and BigInteger) can also be replaced, if they were to cause problems. Method RemovePrimitiveConverstion has been added to aid with removing registered conversions.

Fixes:

  • Fixed regression in serializing empty collection.
  • IConvertibleToken.ToUtcDateTime() could return local date for ITokens under netcoreapp.
  • Fixed possible inconsistency to how ulong is serialized. It should now be written as string, since whole numberic range cannot be read back without loss / overflow exception.
  • Fixed possible problem with how System.Object is serialized if it's boxed value (int, float, bool etc. ).
  • Serializer.ProduceTokens and CachingSerializer.TokensFromType would always omit json object members, it their values were null, regardless of omitNulls setting.
  • Minor improvements to method docs. This is important to mention.

Performance:

  • When targetting any framework above .NET 3.5 deserialization using CachingDeserializer should be faster in case model is supposed to have large collection of objects with some properties. Deserializer uses heuristic, basing on number of items, when to enable optimisation, since it may be costly. Memory usage is generally higher, but when optimisation kicks in, it can actually decrease. I've run some speed comparison to previous build:
number of items 10 30 50 100 1000
improvement -1% 19% 25% 27% 33%
  • IToken internal representation could use slightly less memory.

Next planned release will most likely be stable, ending long streak of versions with breaking changes. I've spent couple of past releases improving tests (alongside other changes), so any next release should be consistently better and safer to use. Migration to this or next version is recommended.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net is compatible.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 3.5

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

  • net5.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.2 1,334 2/6/2022
2.0.1-rc 854 12/11/2021
2.0.0-rc 1,011 7/4/2021
1.5.1 2,241 9/27/2019
1.5.0 1,377 7/27/2019
1.4.0 1,408 6/5/2019
1.3.1 1,594 1/25/2019
1.3.0 1,530 1/1/2019
1.2.2.8 1,916 7/6/2018
1.2.2.7 1,874 6/25/2018
1.2.2.6 1,735 6/9/2018
1.2.2.5 2,037 3/31/2018
1.2.2.2 1,926 10/7/2017
1.2.2.1 1,816 10/4/2017
1.2.2 1,851 10/1/2017
1.2.0.1 1,797 8/15/2017
1.1.0.10 1,933 6/25/2017

New features, bug fixes and performance improvements. Check changelog on nuget.org for details.