Solved

Java toStrting method for recursive debugging info

Posted on 2008-10-14
3
610 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
Comment Utility
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
Comment Utility
this is not a solution at all.
0
 
LVL 1

Accepted Solution

by:
jV247 earned 450 total points
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Prime numbers are natural numbers greater than 1 that have only two divisors (the number itself and 1). By “divisible” we mean dividend % divisor = 0 (% indicates MODULAR. It gives the reminder of a division operation). We’ll follow multiple approac…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

763 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

9 Experts available now in Live!

Get 1:1 Help Now