Skip to content

Commit

Permalink
Merge pull request #1 from Aliothmoon/fix/issue-1984
Browse files Browse the repository at this point in the history
fix(java): Fix the issue caused by not using readCompressedBytesString during deserialization when string compression is enabled.
  • Loading branch information
Aliothmoon authored Dec 30, 2024
2 parents 8d2d124 + 80c8f6b commit 96ad9f2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ public String readString(MemoryBuffer buffer) {
public Expression readStringExpr(Expression strSerializer, Expression buffer) {
if (isJava) {
if (STRING_VALUE_FIELD_IS_BYTES) {
return new Invoke(strSerializer, "readBytesString", STRING_TYPE, buffer);
if (compressString) {
return new Invoke(strSerializer, "readCompressedBytesString", STRING_TYPE, buffer);
} else {
return new Invoke(strSerializer, "readBytesString", STRING_TYPE, buffer);
}
} else {
if (!STRING_VALUE_FIELD_IS_CHARS) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import lombok.Data;
import org.apache.fury.Fury;
import org.apache.fury.FuryTestBase;
import org.apache.fury.collection.Tuple2;
Expand Down Expand Up @@ -160,6 +161,35 @@ public void testJavaStringSimple() {
}
}

@Data
public static class Simple {
private String str;

public Simple(String str) {
this.str = str;
}
}

/** Test for <a href="https://github.com/apache/fury/issues/1984">#1984</a> */
@Test
public void testJavaCompressedString() {
Fury fury =
Fury.builder()
.withStringCompressed(true)
.withLanguage(Language.JAVA)
.requireClassRegistration(false)
.build();

Simple a =
new Simple(
"STG@ON DEMAND Solutions@GeoComputing Switch/ Hub@Digi Edgeport/216 – 16 port Serial Hub");

byte[] bytes = fury.serialize(a);

Simple b = (Simple) fury.deserialize(bytes);
assertEquals(a, b);
}

@Test(dataProvider = "stringCompress")
public void testJavaString(boolean stringCompress) {
Fury fury =
Expand Down

0 comments on commit 96ad9f2

Please sign in to comment.