Git Product home page Git Product logo

binaron.serializer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

binaron.serializer's Issues

Can I use this library for network communication

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?

Guid values

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.

Null pointer exception when serializing a collection of the objects with a null element

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

Cyclic reference

Is it possible to serialize cyclic reference? When I try to do that, I receive a stackoverflow exception.

Question: Does this library suffer from the same security issues that surround BinaryFormatters in .NET (which are marked as obsolete)?

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.

Serialized type '86' is not supported

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.

Long -> Int restores as 0 even if the value is in the range of int

I am not sure whether it should be considered an issue or a feature :-) but let's raise it anyway.

Let' say

  • we have a class A with a long property a
  • we create A.a = 1
  • we serialize it
  • now we have a class 'B' with an int property 'a'
  • if deserialize it...
  • oups... we have 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.

  1. 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).

  2. 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.

Deserialization of nullable enumerator values

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?

DateTimeOffset is not de/serialized

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.

List<int?> restores 0 as values

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};

Problem when working with DateTime type

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.

Lost specific class types

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

include private fields in serialization

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?

Add support of pure IEnumerable classes (instead of ICollection)

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.

Support for IReadOnlyDictionary<string, object>

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>> :-)

Add support for readonly structures

It seems like readonly structures are deserialized with default(T) values in all properties and the parameterized constructor is ignored.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.