General problem mapping objects to data and vice versa (tabbydan)
6 Feb 2003 00:17:06 -0500

          From comp.compilers

Related articles
General problem mapping objects to data and vice versa (2003-02-06)
Re: General problem mapping objects to data and vice versa (Robert A Duff) (2003-02-11)
Re: General problem mapping objects to data and vice versa (Peter Seibel) (2003-02-11)
Re: General problem mapping objects to data and vice versa (John Stracke) (2003-03-09)
Re: General problem mapping objects to data and vice versa (Peter Seibel) (2003-03-14)
| List of all articles for this month |

From: (tabbydan)
Newsgroups: comp.compilers
Date: 6 Feb 2003 00:17:06 -0500
Keywords: OOP, question
Posted-Date: 06 Feb 2003 00:17:06 EST

I have a general problem and am looking for tool suggestions on how to
tackle it, and other suggestions.

I have inherited a codebase (our application code, and supporting 3rd
party code) that is using a "broken" data serialization mechanism
(Java's default serialization of objects to a binary array). I say
broken because, with the current scheme, versioning data is a

So, what I want to do is to plug in a solution whereby the objects in
question are "automatically" serialized to something readable and easy
to parse (thus easy to version).

After consulting with others I have a draft solution*:

Java code (.class or .java files) -> parsing tool (JavaCC, sableCC,
ANTLR, ...) -> mapping logic (takes parser generated data structures
and figures out a mapping strategy to serialize them) -> serialization
tool (Castor, ...)

I was wondering what tools people would recommend for this task?
Would JavaCC, sableCC, ANTLR, or some other program best work for
parsing my code (on the parsing all I want to know is what instance
variables need to be serialized, and if they have get & set methods
(and if so what their names are)). The codebase is nothing nice and
neat, sometimes it adheres to recommended guidelines and sometimes it
doesn't (for getters and setters they aren't always present or well
named, also there are inner classes...). If anyone has a
recommendation on the serialization tool (Castor, or something else)
that would be nice too but I realize that is not a focus of this

Also, what is the feeling about general language compilers? Is there
a push these days to make compilers multifunctional, so that (in
addition to compiling a program for language x) one can have an API to
the compiler code and ask it details about the code? I know sableCC,
ANTLR, and JavaCC are general tools and one can do what they want with
them (so they do this and a whole lot more). However, it seems to me
that if one is programming in a language what one would really like is
for their compiler to give them that info. That is if I use javac to
compile java, I trust it to parse Java code better than anything
else... so it makes the most sence for me to "ask" javac for
information relevant to my code. Unfortunately it seems most all
language compilers (things like javac, not the more general tools like
ANTLR) don't provide this.


supporting notes for *

Castor can't solve my problem by itself because it can only
automatically parse & map classes of two fixed formats (neither of
which are used in my codebase). Hand generating Castor mapping files
is out of the question because it introduces another layer of work and

Likewise xdoclet can't help me because it can only generate Castor
mapping files correctly if the code is commented with metadata tags
(again the solution I am aiming for involves no extra work for the
programming team).

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.