Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hudi.common.util;

import javax.annotation.Nullable;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -88,7 +89,10 @@ public static String nullToEmpty(@Nullable String string) {
}

public static String objToString(@Nullable Object obj) {
return obj == null ? null : obj.toString();
if (obj == null) {
return null;
}
return obj instanceof ByteBuffer ? toHexString(((ByteBuffer) obj).array()) : obj.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.junit.jupiter.api.Test;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;

Expand Down Expand Up @@ -51,6 +52,20 @@ public void testStringNullToEmpty() {
assertEquals("", StringUtils.nullToEmpty(null));
}

@Test
public void testStringObjToString() {
assertNull(StringUtils.objToString(null));
assertEquals("Test String", StringUtils.objToString("Test String"));

// assert byte buffer
ByteBuffer byteBuffer1 = ByteBuffer.wrap("1234".getBytes());
ByteBuffer byteBuffer2 = ByteBuffer.wrap("5678".getBytes());
// assert equal because ByteBuffer has overwritten the toString to return a summary string
assertEquals(byteBuffer1.toString(), byteBuffer2.toString());
// assert not equal
assertNotEquals(StringUtils.objToString(byteBuffer1), StringUtils.objToString(byteBuffer2));
}

@Test
public void testStringEmptyToNull() {
assertNull(StringUtils.emptyToNull(""));
Expand Down