liubiao4123 / servicestack

Automatically exported from code.google.com/p/servicestack
0 stars 0 forks source link

Serializer issue with cyclic object graph #19

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
>What steps will reproduce the problem?
1. There is a cycles in an object model (e.g. Manager->Subordinate->Manager)
2. The following error occured: An item with the same key has already been 
added.
   at ServiceStack.Text.Jsv.JsvWriter`1.WriteObject(TextWriter writer, Object value)
   at ServiceStack.Text.TypeSerializer`1.SerializeToString(T value)
   at ServiceStack.Redis.Generic.RedisTypedClient`1.SerializeValue(T value)
   at ServiceStack.Redis.Generic.RedisTypedClient`1.AddItemToList(IRedisList`1 fromList, T value)
   at ServiceStack.Redis.Generic.RedisClientList`1.Add(T item)
   at RedisClientPrototype.Tester.RedisClientTester.Run() in D:\projects\danware\wiseMo\prototype\RedisClientPrototype\RedisClientPrototype\Tester\RedisClientTester.cs:line 39

>What is the expected output? What do you see instead?
The expected result is the ability of the serializer to handle loops and 
cycles. Currently the application just unfriendly dies with "type initializer 
exception" :(

>What version of the product are you using? On what operating system?
I'm using latest release "Latest release of ServiceStack binaries only (v1.38)".

>Please provide any additional information below.
No additional information

Original issue reported on code.google.com by DZubri...@gmail.com on 13 Jul 2010 at 11:23

Attachments:

GoogleCodeExporter commented 8 years ago
Hi DZubrilin,

Unfortunately cyclic object graphs is a known issue, and not something easily 
solveable. I will accept patches to add this support but due to current time 
constraints not something I will look at solving in the very near future.

When I do I will reply back to you on this thread.

Original comment by demis.be...@gmail.com on 13 Jul 2010 at 11:27

GoogleCodeExporter commented 8 years ago
Hi demis,

Thanks for your reactivity.

But why do implement custom serialization logic? There is at least three 
build-in serializators in .NET (binary/xml/datacontract).
From my point of view binary serializer with Convert.ToBase64String(...) should 
work great in the case. Or maybe I miss something?

Original comment by DZubri...@gmail.com on 13 Jul 2010 at 12:01

GoogleCodeExporter commented 8 years ago
Well, if you check the 
[http://www.servicestack.net/benchmarks/NorthwindDatabaseRowsSerialization.10000
00-times.2010-02-06.html benchmarks] the JSV deserializer is both faster and 
more compact than all the existing .NET serializers. It can also serialize 
non-attributed POCO's with zero-intrusion/config, is a human-readable, 
self-describing text serialization format that can withstand large changes to 
[MigrationsUsingSchemalessNoSql schema versioning] and supports serializing 
advanced constructs like interfaces and 
[http://www.servicestack.net/mythz_blog/?p=314 dynamic late-bound objects].

Seriously base64'ing a binary serialization payload is like the worst of all 
worlds, slow and unreadable/unversionable and only deserialzable with a 
specific version of .NET. Use protobuf-net for a fast interoperable binary 
protocol, although I have a preference for simple human-readable text protocols 
(kind of like what the Internet is built-on i.e. HTTP/HTML).

For a more in-depth reasoning behind the creation of the new format check out:
http://www.servicestack.net/mythz_blog/?p=176

Hope this explains the reasoning/benefits.
- Demis

Original comment by demis.be...@gmail.com on 13 Jul 2010 at 12:43

GoogleCodeExporter commented 8 years ago
Hello, what is the current status of graph support in ServiceStack 
TypeSerializer ? Are  references supported ? Are cyclic object graphs handled 
correctly ?

Is this support on by default or do I have to turn it on manually ? Are all 
types supported ?

Currently I have a class with DataMember attributes with arrays of objects that 
contains circular references. It appears TypeSerialiser just gives up after the 
top level object?

David

Original comment by dmars...@gmail.com on 17 Mar 2011 at 3:28

GoogleCodeExporter commented 8 years ago
Hi, no I'm sorry cyclical references are not supported.
BTW this project is deprecated and new project is located at:

https://github.com/ServiceStack/ServiceStack.Text

Original comment by demis.be...@gmail.com on 17 Mar 2011 at 8:57