You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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));
}
}
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: