Solved

Java toStrting method for recursive debugging info

Posted on 2008-10-14
3
613 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Free Alternative to JIRA 4 90
Eclipse IDE - Cannot copy/paste from console output 8 126
split string containing \r\n in Java 46 38
egit plugin on eclipse 8 28
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now