This is an automated email from the ASF dual-hosted git repository.

THausherr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d66308ff8 TIKA-4859: Accept enum values in JSON config 
case-insensitively (#3097)
6d66308ff8 is described below

commit 6d66308ff81e71a1e9cf62c7faaad69e6c22a8c7
Author: Dominik Schmidt <[email protected]>
AuthorDate: Sun Aug 30 20:04:53 2026 +0200

    TIKA-4859: Accept enum values in JSON config case-insensitively (#3097)
    
    * TIKA-4859 - accept enum values in JSON config case-insensitively, fix the 
no_ocr docs example
    
    * TIKA-4859 - wording: the docs no longer show no_ocr
    
    ---------
    
    Co-authored-by: Tilman Hausherr <[email protected]>
---
 CHANGES.txt                                        |  4 ++
 .../migration-to-4x/migrating-tika-server-4x.adoc  |  2 +-
 .../ROOT/pages/using-tika/server/index.adoc        |  2 +-
 .../config/loader/TikaObjectMapperFactory.java     |  5 ++
 .../config/loader/TikaObjectMapperFactoryTest.java | 53 ++++++++++++++++++++++
 5 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 43f9e90c7f..9a61c586a2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,9 @@
 Release 4.1.0 - unreleased
 
+   * Enum values in JSON configuration are matched case-insensitively, so
+     "no_ocr" works as well as "NO_OCR"; the server docs used the lower-case
+     form in their examples (TIKA-4859).
+
    * The preview image of iWork '09 packages (QuickLook/Thumbnail.jpg) and of
      iWork '18 packages (preview.jpg) is emitted as a THUMBNAIL embedded
      document, as it already was for iWork '13 (TIKA-4854).
diff --git 
a/docs/modules/ROOT/pages/migration-to-4x/migrating-tika-server-4x.adoc 
b/docs/modules/ROOT/pages/migration-to-4x/migrating-tika-server-4x.adoc
index 8471e4b60a..5452390246 100644
--- a/docs/modules/ROOT/pages/migration-to-4x/migrating-tika-server-4x.adoc
+++ b/docs/modules/ROOT/pages/migration-to-4x/migrating-tika-server-4x.adoc
@@ -67,7 +67,7 @@ POST endpoints accept multipart requests with a `file` part 
and optional `config
 # Parse with custom PDF parser settings (requires allowPerRequestConfig)
 curl -X POST http://localhost:9998/tika/config/json \
   -F "[email protected]" \
-  -F 
"config={\"pdf-parser\":{\"ocr\":{\"strategy\":\"no_ocr\"}}};type=application/json"
+  -F 
"config={\"pdf-parser\":{\"ocr\":{\"strategy\":\"NO_OCR\"}}};type=application/json"
 ----
 
 == Breaking Changes
diff --git a/docs/modules/ROOT/pages/using-tika/server/index.adoc 
b/docs/modules/ROOT/pages/using-tika/server/index.adoc
index 4d291ad840..3328c0824e 100644
--- a/docs/modules/ROOT/pages/using-tika/server/index.adoc
+++ b/docs/modules/ROOT/pages/using-tika/server/index.adoc
@@ -246,7 +246,7 @@ POST with multipart for custom per-request configuration:
 ----
 curl -X POST http://localhost:9998/tika/config/json \
   -F "[email protected]" \
-  -F 
"config={\"pdf-parser\":{\"ocr\":{\"strategy\":\"no_ocr\"}}};type=application/json"
+  -F 
"config={\"pdf-parser\":{\"ocr\":{\"strategy\":\"NO_OCR\"}}};type=application/json"
 ----
 
 Valid handler paths under `/tika/`: `text`, `html`, `xml`, `md`, `json` (bare 
`/tika` returns
diff --git 
a/tika-serialization/src/main/java/org/apache/tika/config/loader/TikaObjectMapperFactory.java
 
b/tika-serialization/src/main/java/org/apache/tika/config/loader/TikaObjectMapperFactory.java
index 0a24e71705..10e56d2f3f 100644
--- 
a/tika-serialization/src/main/java/org/apache/tika/config/loader/TikaObjectMapperFactory.java
+++ 
b/tika-serialization/src/main/java/org/apache/tika/config/loader/TikaObjectMapperFactory.java
@@ -19,6 +19,7 @@ package org.apache.tika.config.loader;
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
 import org.slf4j.Logger;
@@ -126,6 +127,10 @@ public class TikaObjectMapperFactory {
         // Ensure enums are properly validated (not just numeric values)
         mapper.configure(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, 
true);
 
+        // Accept enum values in any case ("no_ocr" as well as "NO_OCR"): 
hand-written
+        // requests and older examples spell them either way
+        mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true);
+
         // Catch duplicate keys in JSON objects
         mapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, 
true);
 
diff --git 
a/tika-serialization/src/test/java/org/apache/tika/config/loader/TikaObjectMapperFactoryTest.java
 
b/tika-serialization/src/test/java/org/apache/tika/config/loader/TikaObjectMapperFactoryTest.java
new file mode 100644
index 0000000000..d58e5e2c19
--- /dev/null
+++ 
b/tika-serialization/src/test/java/org/apache/tika/config/loader/TikaObjectMapperFactoryTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.config.loader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.exc.InvalidFormatException;
+import org.junit.jupiter.api.Test;
+
+public class TikaObjectMapperFactoryTest {
+
+    enum Strategy {
+        NO_OCR, AUTO
+    }
+
+    static class Config {
+        public Strategy strategy;
+    }
+
+    @Test
+    public void testEnumValuesAreCaseInsensitive() throws Exception {
+        ObjectMapper mapper = TikaObjectMapperFactory.getMapper();
+        assertEquals(Strategy.NO_OCR,
+                mapper.readValue("{\"strategy\":\"no_ocr\"}", 
Config.class).strategy);
+        assertEquals(Strategy.NO_OCR,
+                mapper.readValue("{\"strategy\":\"NO_OCR\"}", 
Config.class).strategy);
+        assertEquals(Strategy.AUTO,
+                mapper.readValue("{\"strategy\":\"Auto\"}", 
Config.class).strategy);
+    }
+
+    @Test
+    public void testUnknownEnumValueStillFails() {
+        ObjectMapper mapper = TikaObjectMapperFactory.getMapper();
+        assertThrows(InvalidFormatException.class,
+                () -> mapper.readValue("{\"strategy\":\"nope\"}", 
Config.class));
+    }
+}

Reply via email to