39

Does the business value of implementing them exceed the cost? If you implement, you need to change not just your server, but all clients (although you can support both formats and only change clients as needed). That will take time and testing, which is a direct cost. And don't underestimate the time taken to really understand protocol buffers (especially ...


25

Java keeps track of the objects that have been written to the stream, and subsequent instances are written as an ID, not an actual serialized object. So, for your example, if you write instance "a" to the stream, the stream gives that object a unique ID (let's say "1"). As part of the serialization of "a", you have to serialize "b", and the stream gives it ...


23

i maintain apis and somebody before me added protobuf (because it was "faster"). The only thing faster is RTT because of of smaller payload, and that can be fixed with gzipped JSON. The part that is distasteful to me is the relative work to maintain protobuf (compared to JSON). I use java so we use Jackson object mapping for JSON. Adding to a response ...


21

There are definitely pros/cons about using JSON over REST vs. straight up TCP/IP with binary protocol and I think you are already suspecting that binary protocol will be faster. I can't tell you exactly how much faster (and this would depend on a lot of factors), but I would guess maybe 1-2 orders of magnitude difference. At first glance if something is 10-...


16

I generally avoid having the class know how to serialize itself, for a couple of reasons. First, if you want to (de)serialize to/from a different format, you now need to pollute the model with that extra logic. If the model is accessed via an interface, then you also pollute the contract. public class Image { public void toJPG(String filePath) { ... } ...


15

Serialization is mostly used in two areas: prototyping of persistence pretty much every object graph can quickly be made serializable, for quick proof-of-concepts or quick-and-dirty applications this might be faster than setting up a real ORM layer or other persistence system short term storage of almost-arbitrary objects: Applications servers, for ...


13

Where I work, the decision was taken to conceal the use of protobuf. We don't distribute the .proto files between applications, but rather, any application that exposes a protobuf interface exports a client library which can talk to it. I have only worked on one of these protobuf-exposing applications, but in that, each protobuf message corresponds to some ...


13

C has no native support for serializing structures, so you're on your own. The first order approximation is (as stated in other replies) to define it for primitive types, and apply it recursively to larger structures. However, there are lots of devilish details that have to be addressed beyond the simple concept. To name a few: endian order of integers, ...


12

I use object serialization to allow post-mortem analysis in case of an unexpected error in production. The inputs to a calculation are serialized to a data file. If an error is reported, a simple program can reload the inputs and rerun the calculation with a debugger attached. Or a groovy shell can be used to reload the objects and modify them if desired. ...


12

Kinds of objects For purposes of our discussion, let's separate our objects into three different kinds: Business Domain logic These are the objects that get work done. They move money from one checking account to another, fulfill orders, and all of the other actions that we expect business software to take. Domain logic objects normally do not require ...


9

I've done quite a bit of serialization over the years. Here are some things we came up with: Prefer human readable formats over binary formats. I'd generally prefer Xml to Json mainly because you can use Xslt to transform Xml when you need to upgrade the version. Whatever you are serializing stuff as, the deserialization logic and data storage should allow ...


9

Your deserialization test should take a String as its input, and try to produce a present-day object from it. Therefore, all you have to do is revert a copy of your project to an earlier state, save a serialized String, return to the head, and put that string into your test data. Unless I misunderstand your question, you never need to have different versions ...


7

Have a look at the work Google has done with Protocol Buffers. You write a .proto file like this: message Person { required int32 id = 1; required string name = 2; optional string email = 3; } Then you compile it with protoc, the protocol buffer compiler, to produce code in C++, Java, or Python. Then, if you are using C++, you use that code like ...


7

What are the advantages of serialization over non-serialization methods ? Java serialization has some advantages: Built into the system: You don't need to rely on third-party tools, libraries, or configuration. Relatively simple to understand, at least in the beginning. Every developer knows it (or should). Regardless of whether Java devs approve or ...


7

I've had great success using SQLite databases as a file format for graphics applications. Its both very reliable, and being a standard format, its contents are easily viewed/converted by external programs.


6

You could do any other abstraction on top of the byte arrays, that's what serialization libraries do. But to effectively communicate, both sides have to agree on the same (de)serialization format. While there are several semi-standard ones (XML, JSON, MessagePack, Protocol Buffers), there's no real standard, so it's unlikely to include any one on the ...


6

You don't say how exactly are you serializing the Enum, which is important here. I'm going to assume that you serialize it as the underlying integral value. In that case, your current code indeed has a versioning issue, if you add a new value into the middle of the Enum. For example, in your current code, Error is 0, Completed is 1 and Running is 2. Now ...


6

From the fact that in order to transmit any information you need to put all parts of that information into a series of bytes. In order to transmit a record full of information you would have to "serialize" all the bytes that comprise the record, send them over the wire and at the other end would have to deserialize them back into a record. With the advent ...


6

It is not possible to de-serialize an object and also inject a dependency to another, already existing object, in one step in C#, using the standard serialization mechanisms. You will have to use property injection instead, first constructing the object using the deserializer, afterwards injecting the dependency. For most real-world applications, I don't ...


6

One avenue I am considering is to persist and load from a small relational database (I have sqlite in mind). Should I expect this to be much faster? No, you should not expect this. Though it is not completely impossible, to my experience using a relational database for deserializing an object graph is seldom quicker than deserializing from a file. To my ...


6

Simple answer: you don't. If you're serializing data as XML then you have to agree the details of the XML vocabulary with the consumers of the data. Perhaps you define it yourself, perhaps your consumers define it, perhaps it's defined by some standards body. Whichever is the case, whoever defines the vocabulary has the choice either to use namespaces or ...


6

First of all this has nothing to do with StringBuilder or string.Format. The question stays the same no matter how you generate the strings. You are inventing a new serialization format. This means that you must write serialization and deserialization code. Normally, this is not a good idea because it costs time and is error-prone. Use something read-made ...


6

First thing I would check is if using an existing CAD format would not be sufficient. That would not only prevent you from reinventing the wheel, but also improve the interoperability with other CAD programs. Moreover, adapting the terms of such a format like "Layers" and "Entities", instead of using terms like "layouts" and "patterns" (which have typically ...


6

Your member variables are redundant. You should either store the JSONObject or the Strings but not both of them. This will avoid consistency issues. Here is a suggestion: public class RequestParams { private final String student_id; private final String student_name; private final String student_role_number; private final String ...


6

Java serialisation is best avoided. It's full of possible security exploits, it doesn't cope well when your class structure is changed and it creates a "hidden" constructor in your class. It sounds like you want to be able to use some sort of text file format for storing your objects. I would suggest using JSON or XML. But be very careful when reading ...


5

It just means the deserializer has to use the same binary format as the serializer did. For example, consider serializing a string. There are several different binary formats for a string, even though they represent the same data semantically. One way is to first serialize a number representing the length of the string, then write the individual ...


5

it caches the object and uses references so objects are not written out twice 5. If the object has already been written to the stream, its handle is written to the stream and writeObject returns. 12. For regular objects, the ObjectStreamClass for the class of the object is written by recursively calling writeObject. It will appear in the stream only the ...


5

tl;dr I suggest static methods, or even instance methods can be alright depending on the objects you're working with and how long lived they are as well as how stateful they are. Do not use properties for this. Properties should be as idempotent as possible (repeated access should return the same result constantly). If A property needs to execute logic to ...


5

Can a StringBuilder be used to do this? Yes. Can a hammer be used to drive screws into wood. Yes. Both are possible. Neither are a Good Idea. What you're describing is a class that takes a line of text and delivers back to you the object represented by that line. That's could be a Factory class, or simply a "Reader" class responsible for loading ...


Only top voted, non community-wiki answers of a minimum length are eligible