Java Object to String objectToString(final Object value)

Here you can find the source of objectToString(final Object value)

Description

For Visual Studio compatibility.

License

Open Source License

Parameter

Parameter Description
value An object

Return

The string representation of an object

Declaration

public static String objectToString(final Object value) 

Method Source Code

//package com.java2s;
// Licensed under the MIT license. See License.txt in the repository root.

public class Main {
    /**/* w  w  w .  ja va 2 s  .  c  o  m*/
     * For Visual Studio compatibility. Takes an Object and returns a string
     * representation. Generally calls Object.toString(), unless we know that
     * TFS wants a particular type formatted a particular way.
     *
     * @param value
     *        An object
     * @return The string representation of an object
     */
    public static String objectToString(final Object value) {
        if (value instanceof Double) {
            return doubleToString((Double) value);
        } else {
            return value.toString();
        }
    }

    /**
     * For Visual Studio compatibility: converts a Double-type to a String, but
     * ensures that whole numbers have no decimal point.
     *
     * This is for rule engine parsing and display. Ie, when we have a double
     * value "0", we display it as "0.0", while .NET (and C# in general)
     * displays "0". This leads to interop headaches, particularly with
     * ALLOWEDVALUES fields.
     *
     * @param value
     *        A Double to convert to a String
     * @return A String representation of a Double
     */
    public static String doubleToString(final Double value) {
        if (value == null) {
            return null;
        }

        if (value.intValue() == value.doubleValue()) {
            return Integer.toString(value.intValue());
        }

        return value.toString();
    }
}

Related

  1. castString(Object val)
  2. castToString(Object inValue)
  3. castToString(Object object)
  4. castToString(Object value)
  5. castToStringArray(Object[] array)
  6. objectToString(Object a_Object)
  7. objectToString(Object in)
  8. objectToString(Object in, boolean ignoreNull)
  9. objectToString(Object o)