File tree Expand file tree Collapse file tree
sdks/java/core/src/main/java/org/apache/beam/sdk/util Expand file tree Collapse file tree Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments