Class StringConverter

java.lang.Object
org.pipservices3.commons.convert.StringConverter

public class StringConverter extends Object
Converts arbitrary values into strings. Converts using extended conversion rules:
  • Numbers: are converted with '.' as decimal point
  • DateTime: using ISO format
  • Boolean: "true" for true and "false" for false
  • Arrays: as comma-separated list
  • Other objects: using toString() method

### Example ###

 
 String value1 = StringConverter.toString(123.456); // Result: "123.456"
 String value2 = StringConverter.toString(true); // Result: "true"
 String value3 = StringConverter.toString(ZonedDateTime.now()); // Result: "2018-01-01T00:00:00.00"
 String value4 = StringConverter.toString(new int[]{1, 2, 3}); // Result: "1,2,3"
 
 
  • Constructor Details

    • StringConverter

      public StringConverter()
  • Method Details

    • toNullableString

      public static String toNullableString(Object value)
      Converts value into string or returns null when value is null.
      Parameters:
      value - the value to convert.
      Returns:
      string value or null when value is null.
    • toString

      public static String toString(Object value)
      Converts value into string or returns "" when value is null.
      Parameters:
      value - the value to convert.
      Returns:
      string value or "" when value is null.
      See Also:
    • toStringWithDefault

      public static String toStringWithDefault(Object value, String defaultValue)
      Converts value into string or returns default when value is null.
      Parameters:
      value - the value to convert.
      defaultValue - the default value.
      Returns:
      string value or default when value is null.
      See Also: