Class Beans

java.lang.Object
cl.netswitch.lib.util.Beans

public final class Beans extends Object
Provides static utility methods that operate on Java beans.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    copy(Object source, Object destin)
    Calls all setters in a destination object with values obtain from matching getters in a source object.
    static String
    toXML(Object object)
    Converts an object to an XML string representation with no nulls.
    static String
    toXML(Object object, boolean addNulls)
    Converts an object to an XML string representation with or without nulls.
    static String
    toYAML(Object object)
    Converts an object to a YAML string representation with no nulls.
    static String
    toYAML(Object object, boolean addNulls)
    Converts an object to a YAML string representation with or without nulls.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • copy

      public static void copy(Object source, Object destin)
      Calls all setters in a destination object with values obtain from matching getters in a source object.

      In other words, this method executes the following statement for all matching getters and setters.

       destin.setProperty(source.getProperty());
      A getter and setter match if the name and type of their respective properties are exactly the same.
      Parameters:
      source - the object whose getter methods are invoked.
      destin - the object whose setter methods are invoked.
      Throws:
      NullPointerException - if an argument if null.
      IllegalArgumentException - if another error occurs.
    • toXML

      public static String toXML(Object object)
      Converts an object to an XML string representation with no nulls.

      See toXML(Object, boolean) for further details, because this is just a convenience method implemented by the following trivial statement:

      return toXML(object, false);
      Parameters:
      object - the object to be converted to XML (can be null).
      Returns:
      an XML string representation of the supplied object.
      See Also:
    • toXML

      public static String toXML(Object object, boolean addNulls)
      Converts an object to an XML string representation with or without nulls.
      Parameters:
      object - the object to be converted to XML (can be null).
      addNulls - if true null values are added to the result.
      Returns:
      an XML string representation of the supplied object.
    • toYAML

      public static String toYAML(Object object)
      Converts an object to a YAML string representation with no nulls.

      See toYAML(Object, boolean) for further details, because this is just a convenience method implemented by the following trivial statement:

      return toYAML(object, false);
      Parameters:
      object - the object to be converted to YAML (can be null).
      Returns:
      a YAML string representation of the supplied object.
      See Also:
    • toYAML

      public static String toYAML(Object object, boolean addNulls)
      Converts an object to a YAML string representation with or without nulls.
      Parameters:
      object - the object to be converted to YAML (can be null).
      addNulls - if true null values are added to the result.
      Returns:
      a YAML string representation of the supplied object.