zachsaw / binaron.serializer Goto Github PK
View Code? Open in Web Editor NEWBinaron.Serializer - The binary serializer that is up to 150x faster than Newtonsoft.Json!
License: MIT License
Binaron.Serializer - The binary serializer that is up to 150x faster than Newtonsoft.Json!
License: MIT License
Is it possible to serialize cyclic reference? When I try to do that, I receive a stackoverflow exception.
Running into this issue, as well as for type '1', in my project and having a hard time figuring out what type I'm using that is unsupported.
Class is built up of longs,ulongs,ints, uints, doubles, and some struct arrays. Thought it might be the arrays but when I add the 'IgnoreDataMember' attribute to the arrays I still get the same errors. If you could point me in the right direction on what is failing, I'd appreciate it.
Hello,
I have a problem with generic de serialization. I tried to use code from the readme, but it seems not working.
var input = new Employee
{
FirstName = "Hello",
LastName = "Worlds",
BirthDate = DateTime.UtcNow,
};
using (var stream = new MemoryStream())
{
BinaronConvert.Serialize(input, stream, new SerializerOptions
{
SkipNullValues = true,
CustomObjectIdentifierProviders = { new PersonIdentifierProvider() }
});
stream.Position = 0;
// this cause an exception.
var person = BinaronConvert.Deserialize<IPerson>(stream, new DeserializerOptions
{
CustomObjectFactories = { new PersonFactory() }
});
stream.Position = 0;
}
I made a simple project you can see whole source code https://github.com/saatsazov/binaron-test/blob/master/UnitTest1.cs#L70
Test TestMethod3
is failing with this error
Exception has occurred: CLR/System.TypeInitializationException
An exception of type 'System.TypeInitializationException' occurred in Binaron.Serializer.dll but was not handled in user code: 'The type initializer for 'GetObjectReaderGeneric`1' threw an exception.'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception System.NotSupportedException : Interface 'tests.UnitTest1+IPerson' is not supported
at Binaron.Serializer.Accessors.SetterHandler.GetActualType(Type type)
at Binaron.Serializer.Accessors.SetterHandler.CreateActivatorsAndSetters(Type type)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Binaron.Serializer.Accessors.SetterHandler.GetActivatorAndSetterHandlers(Type type)
at Binaron.Serializer.TypedDeserializer.ObjectReaders.CreateReader(Type type)
at Binaron.Serializer.TypedDeserializer.ObjectReaders.CreateReader[T]()
at Binaron.Serializer.TypedDeserializer.GetObjectReaderGeneric`1..cctor()
What I want to achieve is client-server communication via messages. So as I assume messages somehow isolated in stream? By implementing CustomObjectIdentifierProvider we kinda specify message id which should be unique in our protocol. I'm I right?
It seems like readonly structures are deserialized with default(T) values in all properties and the parameterized constructor is ignored.
If a class has a nullable property (e.g. int?) and the property has null
value, a 0
value is restored.
After fixing #34 :-)
Now the same sample
List<int?> l = new List<int?>() { 1, null, 2 };
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(l, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var l1 = BinaronConvert.Deserialize<List<int?>>(ms2);
}
}
returns
l1 = {0, null, 0};
Hello.
I got an Error when I try to serialize a DataTable
Maybe I do something wrong ?
Example code:
List<int?> l = new List<int?>() { 1, null, 2 };
using (var ms1 = new MemoryStream())
{
BinaronConvert.Serialize(l, ms1);
using (var ms2 = new MemoryStream(ms1.ToArray()))
{
var l1 = BinaronConvert.Deserialize<List<int?>>(ms2);
}
}
Serialization causes the null pointer exception.
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Binaron.Serializer
StackTrace:
at Binaron.Serializer.Serializer.WriteObject[T](WriterState writer, T val) in D:\develop\3rdparty\Binaron.Serializer\Binaron.Serializer\src\Binaron.Serializer\Serializer.cs:line 105
Serializer already handles IDictionary<string, object> properly. It would be nice if it had support for IReadOnlyDictionary<string, object> too.
Better yet if it could also work with IReadOnlyDictionary<string, IReadOnlyDictionary<string, object>> :-)
Title says it all. I have not done the reading on what the issue with the built in binary serialization is but I wonder if this library presents the same issue?
Excerpt from: BinaryFormatter serialization methods are obsolete and prohibited in ASP.NET apps
Serialize and Deserialize methods on BinaryFormatter, Formatter, and IFormatter are now obsolete . Additionally, BinaryFormatter serialization is prohibited by default for ASP.NET apps.
Due to security vulnerabilities in BinaryFormatter, the following methods are now obsolete and produce a compile-time warning with ID SYSLIB0011. Additionally, in ASP.NET Core 5.0 and later apps, they will throw a NotSupportedException, unless the web app has re-enabled BinaryFormatter functionality.
Hello,
I'm trying to serialize and deserialize a class with a property that is a nullable enumerator.
However I'm getting the following error when executing the deserializer:
{"Unable to cast object of type 'System.Int32' to type 'System.Nullable`1[DocDigitizer.Common.DataObjects.OrientationEnum]'."}
sample code is something around this:
public class MyClass
{
public string TestString{get;set;}
public TestEnum? TestEnumerator {get;set;}
}
public enum TestEnum
{
Val1 = 1,
Val2 = 2
}
Then in code
MyClass mc1 = new MyClass() { TestString = "Hello", TestEnumerator = TestEnum.Val1 };
var bytes = BinaronUtil.Serialize(mc1);
var mc2 = BinaronUtil.Deserialize<MyClass>(bytes);
The last line fails
(BinaronUtil is just a wrapper we have for invocations of BinaronConvert Serialize and Deserialize methods that will handle by MemoryStream part)
How can I overcome this?
Currently, it seems like that it serializes classes that implement IEnumerable well, but requires ICollection to be implemented to restore.
In fact, it does not need all methods of ICollection at all. void Add(T) method or a constructor that accepts IEnumerable would be sufficient to implement restoration.
Trying to serialize and then deserialize an object with a property of type DateTimeOffset, I get the default value back, instead of the serialized value.
I was wondering if there was any way to convert Guid values?
I've tried using an object with guid properties as well as the object with its properties stored as a Dictionary<string, object> but in both instances the Guids don't work properly.
The object is deserialized with empty Guids, and the dictionary has ExpandoObject values in place of the Guids.
I've had to resort to obj->Json->UTF8 byte[] which has poor performance in comparison.
Lost specific class types
I am serializing a list containing base class instances. When I use System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
I can print the specific class name instances out. But with Binaron I get:
Base Base Base Base
I hoped I could keep the classes specific class names intact when retrieving them. TheBinaryFormatter
does that but is said to be insecure
Can used for serialism and deserialize Json
I am not sure whether it should be considered an issue or a feature :-) but let's raise it anyway.
Let' say
A
with a long
property a
int
property 'a'B.a == 0
I've checked the logic, the current implementation does not even try to restore the value if the size of the target type is less than the size of the target type (e.g. long to int, unit to int, int to short, anything to sbyte, float to double). It always restores 0
in this case.
In fact this only of many possible scenarios:
E.g.
Throw an exception to let the user know that the conversion is impossible (there is plenty of cases where the library throws the exception right now).
Convert the value if the value is in the range of the target type (this is especially important in versioning when we downplay the accuracy of our class because we don't need that much accuracy) and throw the exception otherwise.... or even return default(T) only in case conversion is not possible.
... many others.
I am not sure what this particular variant has been chosen. Adding a little bit of intelligence here won't hurt the performance, but will increase the usability of the code. Interestingly enough, yet the library restores long to float which is a kinda similar situation - you cannot restore long to float exactly, the lower digits will be lost.
If there are no objections, I would implement option 2 or something that we decide works the best. From my perspective, this situation is not unusual, so I definitely would prefer the library to convert the value when it is possible.
I am open to implementing as a part of upcoming PR for read-only structures, however, I would double-check with the author before I start doing that.
It seems that private fields are excluded from serialization. In my project, I would need them to be included. Could there be a flag added to allow that?
When serialized a DateTime object and deserialized, resulted DateTime is in UTC instead of local DateTime. The object clearly shows the Kind is Utc instead of Local.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.