Solved

Java toStrting method for recursive debugging info

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Timer (static) 9 43
How to execute a Python program and gather return output in Java 2 30
runtime exception 2 28
ejb on wildfly 5 20
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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

770 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