View Javadoc
1   package org.pojomatic.formatter;
2   
3   import org.pojomatic.Pojomatic;
4   import org.pojomatic.PropertyElement;
5   
6   /**
7    * Default formatter for classes that use {@link Pojomatic}.  This implementation first presents
8    * the class name, and then each property in turn, separated by commas, using braces to indicate
9    * nesting.
10   * <p>
11   * For example, if a class Person has two properties, firstName and LastName, and these properties
12   * are using {@link DefaultPropertyFormatter}, then the Person
13   * instance representing Joe Blow would be represented as
14   * <code>"Person{firstName: {Joe}, lastName: {Blow}}"</code>
15   *
16   * @deprecated Since 2.0. Use {@link DefaultEnhancedPojoFormatter} instead.
17   */
18  @Deprecated
19  public class DefaultPojoFormatter implements PojoFormatter {
20    private boolean firstPropertyPrinted = false;
21  
22    @Override
23    public String getPropertyPrefix(PropertyElement property) {
24      StringBuilder result = new StringBuilder();
25      if (firstPropertyPrinted) {
26        result.append(", ");
27      }
28      else {
29        firstPropertyPrinted = true;
30      }
31      return result.append(property.getName()).append(": {").toString();
32    }
33  
34    @Override
35    public String getPropertySuffix(PropertyElement property) {
36      return "}";
37    }
38  
39    @Override
40    public String getToStringPrefix(Class<?> pojoClass) {
41      return pojoClass.getSimpleName() + "{";
42    }
43  
44    @Override
45    public String getToStringSuffix(Class<?> pojoClass) {
46      return "}";
47    }
48  }