I have a class that is marked as serializable and have no problem storing it in the Session but when I attempt to save it in the ViewState I get:
Sys.WebForms.PageRequestManagerServerErrorException: Error serializing value
The reason is that view state serialization is done by the LosFormatter class while session serialization is done by the BinaryFormatter class. The two are subtly different and one of these subtle differences is probably causing your problem.
Take a look at this article and the documentation for LosFormatter to see if you can find some clues about what is causing your problem.
Well it also depends what kind of session do you use. If it's in-proc, then serialization doesn't take place at all. Your objects get stored into memory.
Related
I am using a map with Hazelcast :
//When I do :
map.put(gen.newId(), myObject);
myObject is a very complex object and does not implements Serializable.
I thought that putting the config like below was enough for not having to implement serializable :
<map name="myMap">
<in-memory-format>OBJECT</in-memory-format>
</map>
The Hazelcast doc says :
http://docs.hazelcast.org/docs/3.5/manual/html/entryprocessor.html
"When it is stored as an object (OBJECT format), then the entry processor is applied directly on the object. In that case, no serialization or deserialization is performed"
Thanks for any suggestion.
Unfortunately the object will always be deserialized when the map.put is called, no matter the in memory format. This is because normally there are backups and they need to receive a copy as well. So in this case your only way out is to make your object 'serializable'. You can use Java serialization, but you can also rely on something like Kryo to deal with complex object graphs.
I think you could also use more efficient hazelcast specific solutions. Here is a comparison table of the solutions. Portable has been working for me but is a pain in the ass to implement and maintain for big objects. DataSerializable is a more easy solution and looks a lot like Parcelable from Android.
So this seems like a fairly simple answer to a common problem: Infinite loop detected in Jackosn. If, when serializing an object tree, Jackson comes upon an object it has already serialized why doesn't it just ignore it? Is there a way to do this in Jackson, or has someone created something similar?
Why all this mucking around with JsonManagedReference/JsonBackReference, which is completely insufficent if you start serializing child objects (which need a reference to the parent) some of the time and you are serializing parent objects some of the time (which obviously doesn't want the child to refer back to itself)?
It seems like now I have to create custom views that take into account every type of circular reference and use case possible which in any non-trivial ORM is a huge task.
EDIT (October 2012)
Jackson 2.x actual now DOES support identity information handling with #JsonIdentityInfo annotation! So the original answer is bit out of date...
OBSOLETE
Jackson does not support handling of object identity: this is a non-trivial task not so because of identifying shared objects which can be done by traversing object graph (incurring some overhead), but rather in figuring out how to include identity information; which ids to use and how. This in turn is somewhat similar to inclusion of type information, but now adds second dimension of extra wrapping to handle.
Doing this has been requested before, and some thought has gone into figuring out how to do it, but ratio of effort to benefit (i.e. number of requests, how badly it is needed) has been higher than adding other features.
So your best bet is to use wrapper objects and implement this manually, or have a look at XStream which can solve this (when enabled; it adds significant overhead in time) and also has JSON output mode using Jettison.
Implementing this manually for your use case is bit easier than solving the general case: you could start with BeanSerializerModifier to add wrapper handler that can keep track of object identities, and know what to serialize instead as object id.
We have our own caching framework that works well and we like it. We'd like to wire it up to NHibernate rather than take a dependency one of the other caching implementations for NH.
I've written an implementation of NHibernate.Cache.ICache that bridges our framework with NH. I based my implementation almost entirely on this:
https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Caches/Velocity/NHibernate.Caches.Velocity/VelocityClient.cs
One thing that jumped out at me right off the bat is the cache keys in the ICache interface are of type object. Our framework key's the cache using strings. I noticed the Velocity implementation above just does a .ToString() on the key instance that's passed to the Get(object key) and Put(object key) methods. That made me a little nervous.
In my testing it appears the "key" object is of type string and it's the entity name.
My questions:
Is blindly calling .ToString() on the key instance a safe approach (I'm checking for null)?
If this implementation is indeed safe, does that mean it's always a string?
If this is always a string, then why is this of type object?
The NH guys are smarter than me, so the fact it's of type object makes me assume there's something I'm missing here. I really don't want to introduce some obscure, random session management bug with unsafe key usage in my cache implementation.
Any guidance would be appreciated - cheers
I didn't get any responses here, nor on the NH user groups thread [1]. I've concluded that calling key.ToString() in our custom implementation is safe, but I'm sad I didn't get some official guidance on this :(
See the user group thread for a bit more details.
Cheers
[1] http://groups.google.com/group/nhusers/browse_thread/thread/6d47ab21e85eb9b7/988ad6046528e7bc?lnk=gst&q=Custom+Cache#988ad6046528e7bc
What is the need for Action classes to be serializable? When and how does it happen, if at all.
As far as I can tell, it doesn't need to be Serializable, and it was a mistake to make ActionSupport implement that interface.
Here is the best reasoning I have found on the subject (taken from here):
It's very common in web frameworks to use Serializable objects for a
couple or reasons, such as being able to preserve state across a
server restart and for shipping objects around in a cluster.
With that said, (IMHO) I believe it was a design mistake to have
ActionSupport implement Serializable. I don't believe that either of
the above really apply to Action objects since they are short-lived.
The choice of making Actions Serializable should have been left to
the developer and not "forced" by the framework.
This question might not be relevant anymore but I thought this might help.
From Sun developer network:
Object serialization is the process of saving an object's state to a sequence
of bytes, as well as the process of rebuilding those bytes into a live object
at some future time.
So why you might want to serialize your objects? That's when you need to persist their state
so you can use them later or in another JVM. The JVM might be on the same machine or over the network on another machine. I think that's the same case for ActionSupport class. If you extend ActionSupport you'll get the chance to serialize your action and send it over the network to be used in another JVM.
i don't know why it must be so. but action classes must extends ActionSupport. and according to http://struts.apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/ActionSupport.html , ActionSupport implements Serializable. so the answer to the when question, it happens all the time :p
I have read other posts on stack overflow on the issue but my question is a little different..
When storing an object in the Session does PHP save the Complete Object Graph in the session?
I am having problems accessing some of the properties of the Object AFTER it is read from the Session.
The object i am storing has complex type properties with some of them being objects of classes that inherit from other classes, so serializing the object before storing it in the session might be a little "expensive".
What am i missing with Objects and their storage in the Session. Are there limits?
Thank you.
Complex object graphs are serialized fine. Even cyclic references can be serialized. You can't serialize resources though, and certain built-in object types. Generally speaking, serialization is a very expensive operation. You should not rely on it as a shared memory strategy.