Skip to content

Commit 81aac37

Browse files
committed
add back increaseDefaultStreamReadConstraints method for backwards capability
1 parent 3f5128d commit 81aac37

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

sdks/java/core/src/main/java/org/apache/beam/sdk/util/RowJsonUtils.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,38 @@ public class RowJsonUtils {
3838
// The maximum string length for the JSON parser, set to 100 MB.
3939
public static final int MAX_STRING_LENGTH = 100 * 1024 * 1024;
4040

41+
//
42+
private static int defaultBufferLimit;
43+
44+
/**
45+
* Increase the default jackson-databind stream read constraint.
46+
*
47+
* <p>StreamReadConstraints was introduced in jackson 2.15 causing string > 20MB (5MB in 2.15.0)
48+
* parsing failure. This has caused regressions in its dependencies include Beam. Here we
49+
* overwrite the default buffer size limit to 100 MB, and exposes this interface for higher limit.
50+
* If needed, call this method during pipeline run time, e.g. in DoFn.setup.
51+
*/
52+
public static void increaseDefaultStreamReadConstraints(int newLimit) {
53+
if (newLimit <= defaultBufferLimit) {
54+
return;
55+
}
56+
try {
57+
Class<?> unused = Class.forName("com.fasterxml.jackson.core.StreamReadConstraints");
58+
59+
com.fasterxml.jackson.core.StreamReadConstraints.overrideDefaultStreamReadConstraints(
60+
com.fasterxml.jackson.core.StreamReadConstraints.builder()
61+
.maxStringLength(newLimit)
62+
.build());
63+
} catch (ClassNotFoundException e) {
64+
// <2.15, do nothing
65+
}
66+
defaultBufferLimit = newLimit;
67+
}
68+
69+
static {
70+
increaseDefaultStreamReadConstraints(MAX_STRING_LENGTH);
71+
}
72+
4173
/**
4274
* Creates a thread-safe JsonFactory with custom stream read constraints.
4375
*

0 commit comments

Comments
 (0)