Skip to content

Releases: StringEpsilon/PhpSerializerNET

Version 2.1.1

12 Mar 17:28
Compare
Choose a tag to compare

2.1.1 (2025-03-12)

Bugfixes

  • Deserializing into a PhpObjectDictionary with an integer key failed with an invalid cast exception. #43.

Regular changes

  • Some minor performance improvements in the validation step of deserialization.

Version 2.1.0

07 Mar 18:41
Compare
Choose a tag to compare

2.1.0 (2025-03-07)

Features

  • Add support for references (r:1;)

Bugfixes

  • Fixed a bug where integers with a plus sign where deserialized incorrectly
    i:+1; was deserialized as 49.

Version 2.0.1

18 Nov 17:56
Compare
Choose a tag to compare

2.0.1 (2024-11-18)

Bugfixes

  • Fixed validation error when deserializing a list of objects. The deserializer would check the wrong token for it's
    datatype and throw and exception like this:
    Can not deserialize array at position [x] to list: It has a non-integer key 'name' at element [y]
    GH #40
  • Related to the above: Some nested arrays or arrays with object values would never implicetly deserialize into a
    List<object> because the check if the array keys are consecutive integers was faulty.
  • Do not throw when a property or field is decorated with it's own name such as [PhpProperty["A"]] public int A;.

Version 2.0.0

13 Nov 19:13
Compare
Choose a tag to compare

Breaking

  • Now targets .NET 8.0 and .NET 9.0
  • PhpTokenizer class is now internal.
  • Removed support for net6.0 and net7.0.
  • The default implicit type for numeric values is now int instead of long
    1.x: PhpSerialization.Deserialize("i:42;") == 42L
    2.x: PhpSerialization.Deserialize("i:42;") == 42
  • Changed the signature of [PhpPropery(long)] to [PhpPropery(int)] to align with the above change.

Features

  • Added PhpSerialization.DeserializeUtf8(ReadOnlySpan<byte>) overloads for cases in which consumers directly work with
    UTF8 inputs and can skip the re-encoding.
  • Added PhpSerializationFilter attribute base class, allowing customization of class and struct member serialization.
    See the PhpSerializationFilterTest for an example. See also Issue #33.

Regular changes

  • Integers and doubles without a value now give a better error message (i:; and d:;).

Performance

  • Reduced time to decode / re-encode the input string.
  • Reduced memory allocations both in the input re-encoding and the deserialization.
  • Delay the materialization of strings when deserializing. This can avoid string allocations entirely for integers,
    doubles and booleans.
  • Improved performance for implicit deserialization of integers as well as minor improvements for implicit
    deserialization of arrays.
  • Improved serialization performance for strings, integers, IList<T>, ExpandoObject, Dictionaries and PhpDynamicObject

Internal

Split the deserialization into 3 phases:

  1. Validation of the input and counting of the data tokens.
  2. Parsing of the input into tokens
  3. Deserializations of the tokens into the target C# objects/structs.

In version 1.4 and prior, this was a 2 step process. This is slightly slower on some inputs, but overall a little
neater because we're cleanly separating the tasks.


Some benchmark results:

Version Input Mean Allocated
1.4.0 a:0:{} 61.78 ns 248 B
2.0.0 a:0:{} 29.81 ns 80 B
1.4.0 a:3:{i:0;s:5:"Hello";i:1;s:5:"World";i:2;s:6:"FooBar";} 243.96 ns 816 B
2.0.0 a:3:{i:0;s:5:"Hello";i:1;s:5:"World";i:2;s:6:"FooBar";} 149.83 ns 352 B
1.4.0 b:1; 50.49 ns 208 B
2.0.0 b:1; 21.65 ns 72 B
1.4.0 i:2147483647; 79.66 ns 296 B
2.0.0 i:2147483647; 32.13 ns 72 B
1.4.0 N; 45.53 ns 184 B
2.0.0 N; 20.57 ns 48 B
1.4.0 O:8:"stdClass":0:{} 97.71 ns 400 B
2.0.0 O:8:"stdClass":0:{} 56.86 ns 176 B
1.4.0 O:8:"stdClass":2:{s:4:"John";d:3.14;s:4:"Jane";d:2.718;} 307.86 ns 992 B
2.0.0 O:8:"stdClass":2:{s:4:"John";d:3.14;s:4:"Jane";d:2.718;} 206.99 ns 504 B
1.4.0 s:12:"Hello World!"; 72.20 ns 296 B
2.0.0 s:12:"Hello World!"; 36.02 ns 96 B

1.4.0

18 Nov 01:00
Compare
Choose a tag to compare
  • Now targets .NET 6.0, 7.0 and 8.0
  • Improved tokenization performance by allowing and forcing more aggresive inlining.
    • In my benchmark, this is about 8 to 9% faster

1.3.0 - .NET7

10 Nov 18:37
Compare
Choose a tag to compare

1.3.0

  • Removed net5 support and added net7 support
  • Added package icon

Thanks @sommmen for the contributions!

1.2.0

18 Apr 10:45
Compare
Choose a tag to compare

1.2.0

  • Added overload of [PhpProperty()] that accepts integer / long keys. See #32
  • Allow deserialization of Objects with integer keys

1.1.0

17 Jan 21:16
Compare
Choose a tag to compare
  • Made type information caches thread safe. ( #31 by sommmen )
  • Added support for PhpProperty on enums, allowing consumers to specify different field names ( #29 by sommmen)
  • Performance: Cache enum field information with TypeCacheFlag.PropertyInfo.

1.0.0

31 Dec 09:08
Compare
Choose a tag to compare

1.0.0

This is just 0.11.0 packaged as a new version to mark it as stable.

No changes have been made to any of the library code. Only some work on unit tests and documentation.

0.11.0

23 Dec 17:53
Compare
Choose a tag to compare

0.11.0

Deserialization:

  • Added string Serialize(object? input, PhpSerializiationOptions? options = null) to PhpSerialization so the target type can be specified at run time.
  • PhpSerialization (entry point of the library) is now null reference aware, aiding library consumers in caching NullReferenceException.
  • PhpSerialization throws ArgumentOutOfRangeException instead of the more generalised ArgumentException
  • Bugfix: "INF" and "-INF" would not be handled correctly when using explicit typing (Deserialize<T>) for some target types.
  • Bugfix: Properly set classname when deserializing with explicit types that implement IPhpObject.
  • Bugfix: With the AllowExcessKeys, the deserialization of the given struct or object would abort when an excess key was encountered, leaving the properties after the excess key unassigned. See issue #27.
  • Performance tweaks:
    • Minor improvements on memory use during deserialization.
    • Improved performance for deserializing Double and Integer values with explicit types.

General:

  • Bugfix: PhpSerialization.ClearTypeCache() was not exposed.
  • Bugfix: PhpSerialization.ClearPropertyInfoCache() was not exposed.

Plan for 1.0

Plan is to release this version as 1.0 before the new year with no added features or breaking changes. Just bugfixes, should they be needed. Will also need to finish the documentation.