Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BusinessIdentity.toString fails for Pojos containing primitive arrays. #85

Closed
tcurrie opened this issue May 12, 2016 · 1 comment
Closed
Assignees

Comments

@tcurrie
Copy link

tcurrie commented May 12, 2016

Fails in ToStringHelper.nameValuePair:
`
public static String nameValuePair(final Object name, final Object value) {
String valueString = "" + value;
if (value != null && value.getClass().isArray())
valueString = Arrays.deepToString((Object[]) value);
return String.format(NAME_VALUE_TOKEN_FORMAT, name, valueString);
}

`
The cast to Object[] does not work for primitive arrays (though it will work for multi-dimensional primitive arrays).

Here's a simplified example of a test against different primitive types. I think that you'll need to test whether the array is a primitive type and then switch out to cast to each array primitive type.

@Test
public void testPojoToString() {
    Object[] arrays = {
            new int[] {1, 2, 3},
            new int[][]{{1, 2},{3, 4}},
            new float[] {1.1f, 1.2f},
            new float[][] {{1.1f, 2.1f},{3.1f, 4.2f}},
            new double[] {1.1d, 1.2d},
            new double[][] {{1.1d, 2.1d},{3.1d, 4.2d}},
    };

    for (Object arr : arrays)
        printArray(arr);

}

private void printArray(final Object o) {

    System.out.println("isarray [" + o.getClass().isArray()
            + "], type [" + o.getClass().getComponentType()
            + "], primitive [" + o.getClass().getComponentType().isPrimitive() + "]");
    if (o.getClass().getComponentType().isPrimitive()) {
        System.out.println(Arrays.toString((int[])o));
    } else {
        System.out.println(Arrays.deepToString((Object[])o));
    }
}
@oshoukry oshoukry self-assigned this May 12, 2016
@oshoukry oshoukry added this to the Shipping Next milestone May 12, 2016
@oshoukry oshoukry removed this from the Shipping Next milestone May 22, 2017
@oshoukry
Copy link
Member

Fix released in release 0.8.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants