ObjDump is a very small framework that extracts the internals from any Java object and dumps them to a String. The String can then be used in whatever way needed.
Download
Visit the sourceforge project area.
Examples
Given two classes:
class TSomeClass
{
public
int
fInt
= 0;
public
String
fSomeString = "";
public TSomeOtherClass
fSc
= null;
}
class TSomeOtherClass
{
public double
fDbl
= 3.2;
}
and a method:
void test ()
{
TSomeClass foo = new TSomeClass ();
foo.fInt = 10;
foo.fSomeString = "hello world";
foo.fSc
= new TSomeOtherClass ();
foo.fSc.fDbl = 102.7;
String objDumpTxtConcise = GetObjectDumpTextConcise (foo);
String objDumpTxtDetailed = GetObjectDumpTextDetailed (foo);
String
objDumpXML
= GetObjectDumpXML
(foo, 0);
}
The three variables objDumpTxtConcise, objDumpTxtDetailed, objDumpXML would be set to the following content:
objDumpTxtConcise
org.rww.debug.TSomeClass anonymous = 'object' (id = 173a10f)
public java.lang.Integer fInt = '10' (id = a)
public java.lang.String fSomeString = 'hello world' (id = 6aefe2c4)
public org.rww.debug.TSomeOtherClass fSc = 'object' (id = a62fc3)
public java.lang.Double fDbl = '102.7' (id = 8c956001)
objDumpTxtDetailed
--------------------------------------------------------------------------------------------
Object dump:
--------------------------------------------------------------------------------------------
| object ID : 173a10f
| modifiers :
| declared type : org.rww.debug.TSomeClass
| actual type : org.rww.debug.TSomeClass
| field name : anonymous
| value : object
| extra info :
--------------------------------------------------------------------------------------------
| | object ID : a
| | modifiers : public
| | declared type : int
| | actual type : java.lang.Integer
| | field name : fInt
|
|
value : 10
| | extra info :
--------------------------------------------------------------------------------------------
| | object ID : 6aefe2c4
| | modifiers : public
| | declared type : java.lang.String
| | actual type : java.lang.String
| | field name : fSomeString
|
|
value : hello world
| | extra info :
--------------------------------------------------------------------------------------------
| | object ID : a62fc3
| | modifiers : public
| | declared type : org.rww.debug.TSomeOtherClass
|
| actual type :
org.rww.debug.TSomeOtherClass
| | field name : fSc
|
|
value : object
| | extra info :
--------------------------------------------------------------------------------------------
|
|
| object ID
: 8c956001
|
|
| modifiers
: public
|
|
| declared type : double
|
|
| actual type :
java.lang.Double
|
|
| field name :
fDbl
|
|
|
value : 102.7
|
|
| extra info :
--------------------------------------------------------------------------------------------
objDumpXML
<object-dump>
<object>
<info>
<object-id>173a10f</object-id>
<modifiers></modifiers>
<declared-type>org.rww.debug.TSomeClass</declared-type>
<actual-type>org.rww.debug.TSomeClass</actual-type>
<field-name>anonymous</field-name>
<value>object</value>
<extra-info></extra-info>
<is-array>false</is-array>
<is-leaf>false</is-leaf>
<is-null>false</is-null>
<is-primitive>false</is-primitive>
</info>
<fields>
<object>
<info>
<object-id>a</object-id>
<modifiers>public </modifiers>
<declared-type>int</declared-type>
<actual-type>java.lang.Integer</actual-type>
<field-name>fInt</field-name>
<value>10</value>
<extra-info></extra-info>
<is-array>false</is-array>
<is-leaf>true</is-leaf>
<is-null>false</is-null>
<is-primitive>true</is-primitive>
</info>
<fields>
</fields>
</object>
<object>
<info>
<object-id>6aefe2c4</object-id>
<modifiers>public </modifiers>
<declared-type>java.lang.String</declared-type>
<actual-type>java.lang.String</actual-type>
<field-name>fSomeString</field-name>
<value>hello world</value>
<extra-info></extra-info>
<is-array>false</is-array>
<is-leaf>true</is-leaf>
<is-null>false</is-null>
<is-primitive>true</is-primitive>
</info>
<fields>
</fields>
</object>
<object>
<info>
<object-id>a62fc3</object-id>
<modifiers>public </modifiers>
<declared-type>org.rww.debug.TSomeOtherClass</declared-type>
<actual-type>org.rww.debug.TSomeOtherClass</actual-type>
<field-name>fSc</field-name>
<value>object</value>
<extra-info></extra-info>
<is-array>false</is-array>
<is-leaf>false</is-leaf>
<is-null>false</is-null>
<is-primitive>false</is-primitive>
</info>
<fields>
<object>
<info>
<object-id>8c956001</object-id>
<modifiers>public </modifiers>
<declared-type>double</declared-type>
<actual-type>java.lang.Double</actual-type>
<field-name>fDbl</field-name>
<value>102.7</value>
<extra-info></extra-info>
<is-array>false</is-array>
<is-leaf>true</is-leaf>
<is-null>false</is-null>
<is-primitive>true</is-primitive>
</info>
<fields>
</fields>
</object>
</fields>
</object>
</fields>
</object>
</object-dump>
Features
ObjDump provides:
* Different output formats,
* Automatic detection of circular references by using a cache mechanism,
* Automatic limitation of recursion depth.
I hope to be able to introduce further features in the future. Suggestions welcome!
Critique
If you have any suggestions, improvements, comments - feel free to submit them using the sourceforge project area.
History
During work on a Java project I found that I needed something which would allow me to dump the contents of a Java object to a string. I looked on the internet, but it wasn't very easy to find something. After some search I found a page on the internet that showed the source code of what I looked for. It was the Object dumper made by Tobias Dezulian. It was already an excellent piece of software, and very easy to use (one statement only). The listing had a paragraph at the top saying,
This Software is freeware.
Feel free to use/modify/distribute.
which was ideal. So I integrated the file into the Java project I was
working on. Unfortunately I found out that the object dumper wouldn't
dump those parts of an object that were arrays. And my project used
arrays. So, at the end I decided that I would write my own
implementation of an object dumper which would be capable of dumping
arrays as well. I also threw in a few extra features such as different
output formats. The resulting software seemed to work quite well in the
java project, and I greatly enjoyed developing something like this;
especially as I haven't worked with the Java reflection API before.
Since the software is quite new, I gave it a version ID of 0.1 and
declared it as beta software, just to be on the safe side. However, I
have tested it on a few objects and was happy with the result. And from
looking at the source code I didn't see any major defects either. but I
haven't run any extensive tests on the software. However, If it proves
to run stable, and I find time, I may put some more features in and it
may reach 1.0 stage.
Donations
In my view, the best donation possible is when the project is used and helps people. I don't need anything else - my bills are paid, I have a roof over my head, and have enough food and clothes available. So - simply use the software and enjoy it. I can't think of any greater reward than that people find the software useful. It's also a great joy to me if people take the software apart and look into it 'how it works'. I myself enjoy to look at a system and to understand it - even if it's only for the "Wow! That's cool!" factor.
If you are still desperate to donate, I have two suggestions:
Donate kindness to other people.
Sometimes the tone on some of the mailing lists can get quite rude,
especially with newcomers. No-one was born with extensive knowledge in
computing. So, if you find that someone wrote a question on a mailing
list that appears to be too simple - don't give unkind answers.
Kindness goes the other way as well. Some people may be tempted to use
a mailing list as the quick way to get a problem solved. You may find
that searching on google brings you the solution you need. I cannot
count the times that I have benefitted from some research on google.
There is also a guide
from Eric Raymond on 'how to ask questions the smart way'. This article
describes how to ask questions on mailing lists and gives you some
insight on why some questions can yield unfriendly answers.
Donate thankfulness.
I once found a plugin for the firefox web browser (for Windows) that allowed people to upgrade their Operating system via the Windows upgrade. The author wrote it and shared it. It was really sad to see some of the other user's reaction to that plugin; they wrote negative comments about it (how useless this plugin is since it's just a duplication of a Windows feature etc.). I don't think that such reactions are very encouraging to the author. At least it's detrimental to other people who want to contribute plugins. But it's really encouraging if people are thankful, at least for the efforts of somebody.
And finally...
many thanks to the host of this project, sourceforge.net
for their excellent service. I would have put this page as homepage
there, but unfortunately I wasn't able to successfully connect to their
servers due to limitations with my computer setup. So, for the time
being, this is the project's homepage.