Solved

Java toStrting method for recursive debugging info

Posted on 2008-10-14
3
619 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

635 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