serialization

Proper Java classes for reading and writing files?

心不动则不痛 提交于 2019-12-20 10:43:28
问题 Reading some sources about Java file I/O managing, I get to know that there are more than 1 alternative for input and output operations. These are: BufferedReader and BufferedWriter FileReader and FileWriter FileInputStream and FileOutputStream InputStreamReader and OutputStreamWriter Scanner class What of these is best alternative for text files managing? What's best alternative for serialization? What does Java NIO say about it? 回答1: Two kinds of data Generally speaking there are two

Homemade vs. Java Serialization

徘徊边缘 提交于 2019-12-20 10:33:14
问题 I have a certain POJO which needs to be persisted on a database, current design specifies its field as a single string column, and adding additional fields to the table is not an option. Meaning, the objects need to be serialized in some way. So just for the basic implementation I went and designed my own serialized form of the object which meant concatenating all it's fields into one nice string, separated by a delimiter I chose. But this is rather ugly, and can cause problems, say if one of

Custom JsonConverter WriteJson Does Not Alter Serialization of Sub-properties

末鹿安然 提交于 2019-12-20 10:22:37
问题 I always had the impression that the JSON serializer actually traverses your entire object's tree, and executes the custom JsonConverter's WriteJson function on each interface-typed object that it comes across - not so. I have the following classes and interfaces: public interface IAnimal { string Name { get; set; } string Speak(); List<IAnimal> Children { get; set; } } public class Cat : IAnimal { public string Name { get; set; } public List<IAnimal> Children { get; set; } public Cat() {

Custom JsonConverter WriteJson Does Not Alter Serialization of Sub-properties

时光总嘲笑我的痴心妄想 提交于 2019-12-20 10:21:14
问题 I always had the impression that the JSON serializer actually traverses your entire object's tree, and executes the custom JsonConverter's WriteJson function on each interface-typed object that it comes across - not so. I have the following classes and interfaces: public interface IAnimal { string Name { get; set; } string Speak(); List<IAnimal> Children { get; set; } } public class Cat : IAnimal { public string Name { get; set; } public List<IAnimal> Children { get; set; } public Cat() {

Run default serialization logic from JsonConverter

て烟熏妆下的殇ゞ 提交于 2019-12-20 10:18:35
问题 I have a JsonConverter that, depending on an instance specific flag, needs to either run custom serialization logic run the default Json.NET serialization logic How can the default Json.NET serialization logic be ran from a JsonConverter ? Thanks 回答1: Here is an example. Say your class to serialize looks like this: class Foo { public bool IsSpecial { get; set; } public string A { get; set; } public string B { get; set; } public string C { get; set; } } The IsSpecial flag is used to control

What's the most efficient way to deep copy an object in Ruby?

跟風遠走 提交于 2019-12-20 09:53:48
问题 I know that serializing an object is (to my knowledge) the only way to effectively deep-copy an object (as long as it isn't stateful like IO and whatnot), but is one way particularly more efficient than another? For example, since I'm using Rails, I could always use ActiveSupport::JSON , to_xml - and from what I can tell marshalling the object is one of the most accepted ways to do this. I'd expect that marshalling is probably the most efficient of these since it's a Ruby internal, but am I

How to do fast data deserialization in Haskell

谁说胖子不能爱 提交于 2019-12-20 09:53:03
问题 Benchmarking shows that the cereal library takes 100x longer to deserialize a data structure of mine (detailed below) than it takes to read the same data off the drive: benchmarking Read mean: 465.7050 us, lb 460.9873 us, ub 471.0938 us, ci 0.950 std dev: 25.79706 us, lb 22.19820 us, ub 30.81870 us, ci 0.950 found 4 outliers among 100 samples (4.0%) 4 (4.0%) high mild variance introduced by outliers: 53.460% variance is severely inflated by outliers benchmarking Read + Decode collecting 100

Configuration file with list of key-value pairs in python

巧了我就是萌 提交于 2019-12-20 09:48:57
问题 I have a python script that analyzes a set of error messages and checks for each message if it matches a certain pattern (regular expression) in order to group these messages. For example "file x does not exist" and "file y does not exist" would match "file .* does not exist" and be accounted as two occurrences of "file not found" category. As the number of patterns and categories is growing, I'd like to put these couples "regular expression/display string" in a configuration file, basically

Java Object Serialization Performance tips

旧时模样 提交于 2019-12-20 09:38:41
问题 I must serialize a huge tree of objects (7,000) into disk. Originally we kept this tree in a database with Kodo, but it would make thousands upon thousands of Queries to load this tree into memory, and it would take a good part of the local universe available time. I tried serialization for this and indeed I get a performance improvement. However, I get the feeling that I could improve this by writing my own, custom serialization code. I need to make loading this serialized object as fast as

How to serialize a JObject without the formatting?

假如想象 提交于 2019-12-20 09:25:50
问题 I have a JObject (I'm using Json.Net) that I constructed with LINQ to JSON (also provided by the same library). When I call the ToString() method on the JObject , it outputs the results as formatted JSON. How do I set the formatting to "none" for this? 回答1: Call JObject's ToString(Formatting.None) method. Alternatively if you pass the object to the JsonConvert.SerializeObject method it will return the JSON without formatting. Documentation: Write JSON text with JToken.ToString 回答2: You can