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
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "file=@document.pdf" \
-F "config={\"pdf-parser\":{\"ocr\":{\"strategy\":\"no_ocr\"}}};type=application/json"
-F "config={\"pdf-parser\":{\"ocr\":{\"strategy\":\"NO_OCR\"}}};type=application/json"
----

== Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/using-tika/server/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ POST with multipart for custom per-request configuration:
----
curl -X POST http://localhost:9998/tika/config/json \
-F "file=@document.pdf" \
-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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -126,6 +127,10 @@ public static ObjectMapper createMapper(JsonFactory factory) {
// 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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}