serialization

Getting NotSerializableException on a serializable object

故事扮演 提交于 2019-12-20 04:51:29
问题 Basically, I've written a program that paints shapes onto the screen, and saves each of the shapes into an ArrayList. What I want to do is figure out how to save the ArrayList to a file, so that I can call it back up later and edit the already existing shapes. So I've been having some trouble figuring out why exactly I keep getting a NotSerializableException when I made the object Shape serializable already. Below is the save portion of my code, and the Shape object. save.addActionListener

Is there some way to specify a custom deserializer for a type that is nested inside an Optional for Jackson?

谁说胖子不能爱 提交于 2019-12-20 04:51:10
问题 I have some types which need to be handled with their own special deserializers and serializers, but how do I instruct Jackson to use them when the type is nested inside an Optional? I am using the JDK8Module which works great for any type not needing any special handling. The @JsonDeserialize and @JsonSerialize annotations don't seem to have any way to apply to the value inside an Optional when they are used on an Optional field: @JsonDeserialize(?????) Optional<SpecialType> myField 回答1: The

Is there some way to specify a custom deserializer for a type that is nested inside an Optional for Jackson?

倖福魔咒の 提交于 2019-12-20 04:51:06
问题 I have some types which need to be handled with their own special deserializers and serializers, but how do I instruct Jackson to use them when the type is nested inside an Optional? I am using the JDK8Module which works great for any type not needing any special handling. The @JsonDeserialize and @JsonSerialize annotations don't seem to have any way to apply to the value inside an Optional when they are used on an Optional field: @JsonDeserialize(?????) Optional<SpecialType> myField 回答1: The

Boost serialization of derived class with private members

让人想犯罪 __ 提交于 2019-12-20 04:48:09
问题 I try to serialize a class, say B (in file b.h), which is derived from another one, say A (in file a.h). Both classes have private members and I want to serialize both with the boost serialization library non-intrusively. The serialization/deserialization of A does work so far. For the same for the derived class one would use ar & boost::serialization::base_object<base_class>(*this); when the intrusive method is used, but where to put it in the non-intrusive case (save/load/serialize or all

Jackson-Serialiser: Ignore Field at Serialisation Time

假如想象 提交于 2019-12-20 04:47:22
问题 My situation asks for a bit more complex serialisation. I have a class Available (this is a very simplified snippet): public class Available<T> { private T value; private boolean available; ... } So a POJO class Tmp { private Available<Integer> myInt = Available.of(123); private Available<Integer> otherInt = Available.clean(); ... } would normally result in {"myInt":{available:true,value:123},"otherInt":{available:false,value:null}} However, I want a serialiser to render the same POJO like

Converting a Binary Tree into an Array (and later save) in C

白昼怎懂夜的黑 提交于 2019-12-20 04:37:01
问题 So, I'm doing this customer application where you can create/Modify/Search/List Customers. Later on this expands to linking customers to products with an order and so on, but my focus right now is just on customers. I have created a binary tree and all these functions work, however I need a way to store created customers for another time. I figured that in some way I would have to transfer all the customers (found in each node) into an array, and then fwrite that array into a file "customer

Dynamic addition of fasterxml Annotation?

不想你离开。 提交于 2019-12-20 04:27:18
问题 Is there a way to set @JsonProperty annotation dynamically like: class A { @JsonProperty("newB") //adding this dynamically private String b; } or can I simply rename field of an instance? If so, suggest me an idea. Also, in what way an ObjectMapper can be used with serialization? 回答1: Assume that your POJO class looks like this: class PojoA { private String b; // getters, setters } Now, you have to create MixIn interface: interface PojoAMixIn { @JsonProperty("newB") String getB(); } Simple

Serialize object to XML WITHIN a parent element

时光总嘲笑我的痴心妄想 提交于 2019-12-20 04:23:17
问题 I've got a WPF C# program and at one point I need to serialize objects to XML. In other places, I've been using this: TextWriter writer = new StreamWriter(xmlFilePath); XmlSerializer xmlSerializer = new XmlSerializer(typeof(MYOBJECT_TYPE)); try { xmlSerializer.Serialize(writer, MYOBJECT); } catch (Exception ex) { MessageBox.Show("Exception occured while writing to Xml" + ex.Message); } finally { writer.Close(); } This is fantastic, but this means I have to have a different XML file for every

protobuf-net and interface support

若如初见. 提交于 2019-12-20 03:56:17
问题 This question directly in large part to the protobuf-net maintainer(s) but anyone else please comment. I was trying to serialize a class that contains a property which has an interface type, ie: [DataContract] public class SampleDataClass { [DataMember(Order=1)] public int Field1 { get; set; } [DataMember(Order = 2)] public IPayload Payload { get; set; } } [ProtoContract] [ProtoInclude(1, typeof(Payload))] public interface IPayload { int Field4 { get; set; } } [DataContract] public class

How avoid infinite loop during Json Serialization in Java

旧城冷巷雨未停 提交于 2019-12-20 03:52:48
问题 I retrieve a list of Brothers using hibernate public class Brother { public int brotherId; public string name; public List<Brother> brothers; public Brother() { brothers = new ArrayList<Brother>(); } //Getter Setter } Hibernate is configured using lazy select in brothers list, this in Java side works, But the problem is when I want to serialize a Brother object to JSON. I've got org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) for Example Bryan can have