serialization

Java Serializable, ObjectInputstream, Non-blocking I/O

依然范特西╮ 提交于 2019-12-22 04:53:30
问题 I'm just starting out with Java serialization, and I'm not clear on how you are supposed to get objects from a source in a scenario with non-blocking I/O . All the documentation I can find suggests using ObjectInputStream is the proper way to read in serialized objects. However, as I mentioned I'm using java.nio and performing non-blocking operations. If readObject() will block until a new object is available, this can't help me Summary .. How do you do serialization when working with Java

How to trigger calls to .serializeWithType() of a class implementing JsonSerializable in Jackson?

会有一股神秘感。 提交于 2019-12-22 04:51:18
问题 This is Jackson 2.2.x. I have a class implementing JsonSerializable; there are two methods to implement for this interface, serialize() and serializeWithType() . I want to test {de,}serialization of this class, and I can trigger calls to serialize() easily; not, however, serializeWithType() . The javadoc for this latter method says that this method is called [...] when additional type information is expected to be included in serialization, for deserialization to use. I just don't understand

Ignore some properties in runtime when using DataContractSerializer

扶醉桌前 提交于 2019-12-22 04:45:12
问题 I am using DataContractSerializer to serialize an object to XML using DataMember attribute (only public properties are serialized). Is it possible to dynamically ignore some properties so that they won't be included in the XML output? For example, to allow user to select desired xml elements in some list control and then to serialize only those elements user selected excluding all that are not selected. Thanks 回答1: For the list scenario, maybe just have a different property, so instead of:

Java serialization bug when facing circular dependency with a Set

[亡魂溺海] 提交于 2019-12-22 04:43:34
问题 My project is a java project over EJB3 using Hibernate and Weblogic server. For convenience sake (and as far as I understand, is typical to hibernate ), some of the entities contains circular dependency (Parent knows the child, child know the parent). Further, for some of the child classes - the hashCode() and equals() method depend on their parent (As it is a unique key). When working I saw an odd behavior - Some of the Sets that returned from the server to the client, although containing

OutOfMemoryError calling XmlSerializer.Deserialize() - not related to XML size!

折月煮酒 提交于 2019-12-22 04:36:09
问题 This is a really crazy bug. The following is throwing an OutOfMemoryException , for XML snippits that are very short and simple (e.g., <ABC def='123'/> ): public static T DeserializeXmlNode<T>(XmlNode node) { try { return (T)new XmlSerializer(typeof(T)) .Deserialize(new XmlNodeReader(node)); } catch (Exception ex) { throw; // just for catching a breakpoint. } } I read in this MSDN article that if I were using XmlSerializer with additional parameters in the constructor, I'd end up generating

OutOfMemoryError calling XmlSerializer.Deserialize() - not related to XML size!

孤者浪人 提交于 2019-12-22 04:36:08
问题 This is a really crazy bug. The following is throwing an OutOfMemoryException , for XML snippits that are very short and simple (e.g., <ABC def='123'/> ): public static T DeserializeXmlNode<T>(XmlNode node) { try { return (T)new XmlSerializer(typeof(T)) .Deserialize(new XmlNodeReader(node)); } catch (Exception ex) { throw; // just for catching a breakpoint. } } I read in this MSDN article that if I were using XmlSerializer with additional parameters in the constructor, I'd end up generating

Why is this JSON returning as “Invalid JSON primitive”?

微笑、不失礼 提交于 2019-12-22 04:35:18
问题 The following JSON is not deserializing. It's obviously because the DECIMALS in the saves JSON. How do I fix this? This initial JSON comes from the server and IS VALID: { "AppropriationAmount": 25000000, "AppropriationHours": 56300, "ArrThreshold": 11, "ClientKey": 24, "Description": 'Find and incarcerate the escaped prisoner', "DirectHours": 50000, "EndDate": '3/31/2011', "EngineeringHours": 4000, "IndirectHours": 2000, "Key": 1589, "Number": '0', "OtherHours": 300, "ProductivityCurveType":

Trigger function on deserialization

我与影子孤独终老i 提交于 2019-12-22 04:34:12
问题 I have a class with a number of fields which are normally calculated in the constructor from other data in the class. They are not serialized to XML because any changes to the rest of the data will likely require their recalculation. Is there a way I can set up a function call to be triggered on deserialization? 回答1: What you are describing is [OnDeserialized] XmlSerializer does not support serialization callback methods (at least, not in MS .NET; mono may be different). Depending on your

Avoiding duplicate objects in Java deserialization

我是研究僧i 提交于 2019-12-22 04:34:08
问题 I have two lists (list1 and list2) containing references to some objects, where some of the list entries may point to the same object. Then, for various reasons, I am serializing these lists to two separate files. Finally, when I deserialize the lists, I would like to ensure that I am not re-creating more objects than needed. In other words, it should still be possible for some entry of List1 to point to the same object as some entry in List2. MyObject obj = new MyObject(); List<MyObject>

Avoiding duplicate objects in Java deserialization

帅比萌擦擦* 提交于 2019-12-22 04:34:01
问题 I have two lists (list1 and list2) containing references to some objects, where some of the list entries may point to the same object. Then, for various reasons, I am serializing these lists to two separate files. Finally, when I deserialize the lists, I would like to ensure that I am not re-creating more objects than needed. In other words, it should still be possible for some entry of List1 to point to the same object as some entry in List2. MyObject obj = new MyObject(); List<MyObject>