Solved

Java toStrting method for recursive debugging info

Posted on 2008-10-14
3
617 Views
Last Modified: 2013-11-13
I am looking for a short working program written in java language that will output (write to String which it would return) all property names and values of the passed parameter if value is string or primitives or wrappers around primitives like Integer. If the value is another property then it recursively does the same with this property and so on. It must also output dynamically added properties (not defined in the class). The output should be in format like;

class_name {
   color=blue
   another_class_name {
       size=large
   }
   .......
}

public String outputpit(Class obj)
0
Comment
Question by:zenguru
3 Comments
 
LVL 12

Assisted Solution

by:marklorenz
marklorenz earned 50 total points
ID: 22766822
The easiest way is to define a toString() method which contains the information you want (of course, you can call it any name, but toString() is the expected method).
0
 

Author Comment

by:zenguru
ID: 22770364
this is not a solution at all.
0
 
LVL 1

Accepted Solution

by:
jV247 earned 450 total points
ID: 22857083
This solution is generic to Java. Basically, use the Apache commons-lang:

http://commons.apache.org/lang/userguide.html

Inside it, you'd see a ToStringBuilder, documented in:

http://commons.apache.org/lang/api/org/apache/commons/lang/builder/ToStringBuilder.html
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question