File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Another ways to serialize Object in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Another ways to serialize Object in Java" Watch "Another ways to serialize Object in Java" New topic
Author

Another ways to serialize Object in Java

Robert Raps
Ranch Hand

Joined: Mar 13, 2013
Posts: 30
Hello, guys, i need some advices.
Propose another ways serialization objects in java.
This is for studying, not for practical using.
I have couples opinion, first- Output stream- printWrite, and add to every classes, instance variables its personal tag, something like:
1) Class cat{
Integer weight;
String name;
}
Then file with dates will be :
<<ObjectClass> cat
<weight> weight ( number, off course that represents this weight)
<name> Jack
<ObjectClass>>
where << and >> bound one object.
2) Other realization is to collect all NAME of instance variables in one array list for example, and then sort them by alphabet.
It helps us such way- we needn't to write Name of every variables, because they will be added in strict sequence, and then can be read in the same order :
<<cat>12; Albert>>

Please, estimate, criticize and offer your variants!))
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3947
    
  17

Robert Raps wrote:Propose another ways serialization objects in java.

Why? There are already several good mechanisms that are general and well supported. Why build your own?
Robert Raps wrote:2) Other realization is to collect all NAME of instance variables in one array list for example, and then sort them by alphabet.
It helps us such way- we needn't to write Name of every variables, because they will be added in strict sequence, and then can be read in the same order :
<<cat>12; Albert>>

Until you have a new version of the class or subclass which has a new variable or a variable is renamed. Then there is incompatibility issues and it would be really hard to version-check. Additionally, you would get into a parsing night-mare (I hope no text which ever gets into your objects has a semi-colon or double brackets...).

Robert Raps wrote:Please ... offer your variants!

Why create your own serialization language and system? Why not use serialization or externalization? My variant would be to use what is standard.


Steve
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

I think that the issue you may have is this:

What happens if the object changes? What if in six months, you need to add a 'birthdate'? and then two months after that, you need to add 'color'? and so forth?

Each time something changes, you have to re-work ALL of your code to write it or read it.

I think that using the build in serialize functions, you don't have to worry about that. You just add the new members and you're done (at least with the serialize part).


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Robert Raps
Ranch Hand

Joined: Mar 13, 2013
Posts: 30
Steve Luke wrote:
Robert Raps wrote:Propose another ways serialization objects in java.

Why? There are already several good mechanisms that are general and well supported. Why build your own?
Robert Raps wrote:2) Other realization is to collect all NAME of instance variables in one array list for example, and then sort them by alphabet.
It helps us such way- we needn't to write Name of every variables, because they will be added in strict sequence, and then can be read in the same order :
<<cat>12; Albert>>

Until you have a new version of the class or subclass which has a new variable or a variable is renamed. Then there is incompatibility issues and it would be really hard to version-check. Additionally, you would get into a parsing night-mare (I hope no text which ever gets into your objects has a semi-colon or double brackets...).

Robert Raps wrote:Please ... offer your variants!

Why create your own serialization language and system? Why not use serialization or externalization? My variant would be to use what is standard.

Obviously << and >> won't be exist in code, but in file where i will try to keep my datas.
I want to parse, because it is task not for practical, but studying goal. I try to use Regular Expression.
Robert Raps
Ranch Hand

Joined: Mar 13, 2013
Posts: 30
fred rosenberger wrote:I think that the issue you may have is this:

What happens if the object changes? What if in six months, you need to add a 'birthdate'? and then two months after that, you need to add 'color'? and so forth?

Each time something changes, you have to re-work ALL of your code to write it or read it.

I think that using the build in serialize functions, you don't have to worry about that. You just add the new members and you're done (at least with the serialize part).

It's for studying. So, please, suggest some destination. More ideas it is better.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Another ways to serialize Object in Java
 
Similar Threads
Array Assignment
What is the different between Object and Context ?
Soting objects in collection
ApacheDS 1.0.2 LDAP java.net.ConnectException: Connection timed out: connect
Serialization