JsonPack 1.0.5.4
See the version list below for details.
dotnet add package JsonPack --version 1.0.5.4
NuGet\Install-Package JsonPack -Version 1.0.5.4
<PackageReference Include="JsonPack" Version="1.0.5.4" />
paket add JsonPack --version 1.0.5.4
#r "nuget: JsonPack, 1.0.5.4"
// Install JsonPack as a Cake Addin
#addin nuget:?package=JsonPack&version=1.0.5.4
// Install JsonPack as a Cake Tool
#tool nuget:?package=JsonPack&version=1.0.5.4
Installation
NuGet packages
To install with NuGet, just install the JsonPack
package:
Install-Package JsonPack
Quick Start
public class MyClass
{
public int Age { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
[IgnoreDataMember]
public string FullName { get; set; }
}
Call JsonPackSerializer.ToJsonString<T>/JsonPackSerializer.Deserialize
to serialize/deserialize your object instance
You can also use JsonPackSerializer.Serialize<T>
method to serialize to byte array instead.
class Program
{
static void Main(string[] args)
{
var mc = new MyClass
{
Age = 69,
FirstName = "Foo",
LastName = "Bar",
};
// Call ToJsonString/Deserialize, that's all.
string json = JsonPackSerializer.ToJsonString(mc);
MyClass mc2 = JsonPackSerializer.Deserialize<MyClass>(json);
}
}
Object Serialization
JsonPack for C# can serialize your own public class
or struct
types, but is not limited to it and can be extended with custom formatters to support external types as well.
Attribution
JsonPackContract Attribte
Apply MemberSerialization
option to specify member serialization.
// `OptOut` All public members are serialized by default.
[JsonPackContract(MemberSerialization = MemberSerialization.OptOut)]
public class Sample1
{
public int Foo { get; set; }
private int Bar { get; set; }
}
// Only members marked with `DataMemberAttribute` are serialized.
[JsonPackContract(MemberSerialization = MemberSerialization.OptIn)]
public class Sample2
{
[DataMember]
public int Foo { get; set; }
private int Bar { get; set; }
}
// All public and private fields are serialized.
[JsonPackContract(MemberSerialization = MemberSerialization.Fields)]
public class Sample3
{
public int Foo { get; set; }
private int Bar { get; set; }
}
Apply SkipConstructor
option to explicitly skip the constructor call on deserialization
[JsonPackContract(SkipConstructor = true)]
public class Sample1
{
public int Foo { get; set; }
}
JsonPackConstructor Attribute
Allows to specify a constructor to be used for deserialization.
public class Sample1
{
public int Foo { get; private set; }
[JsonPackConstructor]
private Sample1(int foo)
{
Foo = foo;
}
}
JsonPackFormatter Attribute
Allows to place a custom JsonPackFormatter<T>
for you own class
or struct
or member
[JsonPackFormatter(typeof(MySample1Formatter))]
public class Sample1
{
public int Foo { get; set; }
}
public class Sample2
{
[JsonPackFormatter(typeof(MyFooFormatter))]
public int Foo { get; set; }
}
JsonPackNullValueAttribute
Defines the null value handling option for a specific member.
This overrides the option provided by JsonPackSerializerOptions
.
public class Sample1
{
// Ignore null values when serializing and deserializing objects.
[JsonPackNullValue(NullValueHandling.Ignore)]
public string Foo { get; set; }
}
public class Sample2
{
// Include null values when serializing and deserializing objects.
[JsonPackNullValue(NullValueHandling.Include)]
public string Foo { get; set; }
}
JsonPackAutoMapper Attribute
Allows to specify additional member name mappings.
public class Sample1
{
[JsonPackAutoMapper("OldFoo", "NewFoo")]
public string Foo { get; set; }
}
Serialization Events
Add custom serialization events for OnSerializing
and OnDeserialized
.
public class Sample1
{
public Foo { get; set; }
[DataMember(Name = "Value")]
private string _serializeOnlyValue;
[OnSerializing]
private void OnSerializing(StreamingContext context)
{
_serializeOnlyValue = "Sample1 was serialized";
}
[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
// Override Foo with _serializeOnlyValue
Foo = _serializeOnlyValue;
}
}
Json Pack Serializer Options
Create custom serialization and deserialization options for the JsonPackSerializer
.
Resolver
var options = JsonPackSerializerOptions.WithResolver(WithImmutableDefaultResolver);
// Use as `DefaultOptions`.
JsonPackSerializer.DefaultOptions = options;
// Use as `parameter` on serialization calls.
var data = JsonPackSerializer.Serializate("FooBar", options);
var str = JsonPackSerializer.Deserializer<string>(data, options);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. 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 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 is compatible. 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. |
-
.NETFramework 4.7
- No dependencies.
-
.NETStandard 2.0
- System.Reflection.Emit (>= 4.7.0)
- System.Reflection.Emit.Lightweight (>= 4.7.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on JsonPack:
Package | Downloads |
---|---|
JsonPack.Extension
An extension for JsonPack to add serialization shortcuts. |
|
JsonPack.ImmutableCollection
ImmutableCollection Formatter Extension for JsonPack. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.2.3 | 184 | 8/24/2023 |
2.2.2 | 126 | 8/24/2023 |
2.2.1 | 108 | 8/23/2023 |
2.2.0 | 117 | 8/22/2023 |
2.1.0 | 115 | 8/18/2023 |
2.0.5 | 120 | 8/17/2023 |
2.0.4 | 129 | 8/11/2023 |
2.0.3 | 117 | 8/10/2023 |
2.0.2 | 111 | 8/10/2023 |
2.0.1 | 121 | 8/7/2023 |
2.0.0 | 174 | 8/6/2023 |
1.0.5.4 | 394 | 10/15/2022 |
1.0.5.3 | 368 | 10/15/2022 |
1.0.5.2 | 357 | 10/14/2022 |
1.0.5.1 | 633 | 6/6/2020 |
1.0.5 | 594 | 6/3/2020 |
1.0.4.3-RC1 | 286 | 6/2/2020 |
1.0.4.2-RC1 | 259 | 6/2/2020 |
1.0.4.1-RC1 | 298 | 6/1/2020 |
1.0.4-RC1 | 301 | 6/1/2020 |
1.0.3.4-beta | 326 | 5/29/2020 |
1.0.3.3-beta | 272 | 5/29/2020 |
1.0.3.2-beta | 280 | 5/28/2020 |
1.0.3.1-beta | 307 | 5/28/2020 |
1.0.3-beta | 257 | 5/27/2020 |
1.0.2.3-beta | 265 | 5/27/2020 |
1.0.2.2-beta | 250 | 5/27/2020 |
1.0.2.1-beta | 443 | 5/27/2020 |
1.0.2-beta | 552 | 5/26/2020 |
1.0.1.15-alpha | 450 | 5/25/2020 |
1.0.1.14-alpha | 414 | 5/24/2020 |
1.0.1.13-alpha | 316 | 5/24/2020 |
1.0.1.12-alpha | 299 | 5/21/2020 |
1.0.1.11-alpha | 322 | 5/21/2020 |
1.0.1.10-alpha | 286 | 5/21/2020 |
1.0.0.7-alpha | 284 | 5/20/2020 |
1.0.0.6-alpha | 293 | 5/19/2020 |
1.0.0.5-alpha | 279 | 5/19/2020 |
1.0.0.4-alpha | 307 | 5/18/2020 |
1.0.0.3-alpha | 303 | 5/18/2020 |
1.0.0.2-alpha | 273 | 5/16/2020 |
1.0.0.1-alpha | 268 | 5/15/2020 |