• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another ways to serialize Object in Java

 
Robert Raps
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Robert Raps
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic