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

tballison 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 0d9d5a43ff swap jackson for gson in the GeoGazetteerClient (#3435)
0d9d5a43ff is described below

commit 0d9d5a43ff1b9d3c0750cd198e613c9486272c70
Author: Tim Allison <[email protected]>
AuthorDate: Tue Oct 27 12:07:57 2026 -0400

    swap jackson for gson in the GeoGazetteerClient (#3435)
---
 .../tika-parsers-ml/tika-parser-nlp-module/pom.xml |  4 +-
 .../geo/topic/gazetteer/GeoGazetteerClient.java    | 22 +++++----
 .../topic/gazetteer/GeoGazetteerClientTest.java    | 52 ++++++++++++++++++++++
 3 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/pom.xml 
b/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/pom.xml
index e4c1516bca..e192151cd7 100644
--- a/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/pom.xml
+++ b/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/pom.xml
@@ -98,8 +98,8 @@
             <artifactId>commons-codec</artifactId>
         </dependency>
         <dependency>
-            <groupId>com.google.code.gson</groupId>
-            <artifactId>gson</artifactId>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
diff --git 
a/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java
 
b/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java
index e1965c937f..b6a98a7edd 100644
--- 
a/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java
+++ 
b/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClient.java
@@ -16,13 +16,14 @@
  */
 package org.apache.tika.parser.geo.topic.gazetteer;
 
-import java.lang.reflect.Type;
+import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Map;
 
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.commons.io.IOUtils;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -42,6 +43,10 @@ public class GeoGazetteerClient {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(GeoGazetteerClient.class);
 
+    // gson ignored fields Location doesn't have
+    private static final ObjectMapper MAPPER =
+            new 
ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+
     private String url;
 
     /**
@@ -74,11 +79,7 @@ public class GeoGazetteerClient {
             HttpResponse resp = httpClient.execute(httpGet);
             String respJson = IOUtils.toString(resp.getEntity().getContent(), 
StandardCharsets.UTF_8);
 
-            @SuppressWarnings("serial") Type typeDef =
-                    new TypeToken<Map<String, List<Location>>>() {
-                    }.getType();
-
-            return new Gson().fromJson(respJson, typeDef);
+            return parseLocations(respJson);
 
         } catch (Exception e) {
             LOG.error(e.getMessage(), e);
@@ -87,6 +88,11 @@ public class GeoGazetteerClient {
         return null;
     }
 
+    static Map<String, List<Location>> parseLocations(String json) throws 
IOException {
+        return MAPPER.readValue(json, new TypeReference<Map<String, 
List<Location>>>() {
+        });
+    }
+
     /**
      * Ping lucene-geo-gazetteer API
      *
diff --git 
a/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/test/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClientTest.java
 
b/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/test/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClientTest.java
new file mode 100644
index 0000000000..8d763d2bcb
--- /dev/null
+++ 
b/tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/test/java/org/apache/tika/parser/geo/topic/gazetteer/GeoGazetteerClientTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.parser.geo.topic.gazetteer;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+public class GeoGazetteerClientTest {
+
+    @Test
+    public void testParseLocations() throws Exception {
+        // lucene-geo-gazetteer sends coordinates as numbers, and fields 
Location doesn't have
+        String json = 
"{\"Pasadena\":[{\"name\":\"Pasadena\",\"countryCode\":\"US\",\"admin1Code\":\"CA\","
+                + 
"\"admin2Code\":\"037\",\"latitude\":34.14778,\"longitude\":-118.14452,\"population\":141029}],"
+                + "\"Nowhere\":[]}";
+        Map<String, List<Location>> locations = 
GeoGazetteerClient.parseLocations(json);
+        assertEquals(2, locations.size());
+        assertTrue(locations.get("Nowhere").isEmpty());
+        Location loc = locations.get("Pasadena").get(0);
+        assertEquals("Pasadena", loc.getName());
+        assertEquals("US", loc.getCountryCode());
+        assertEquals("CA", loc.getAdmin1Code());
+        assertEquals("037", loc.getAdmin2Code());
+        assertEquals("34.14778", loc.getLatitude());
+        assertEquals("-118.14452", loc.getLongitude());
+    }
+
+    @Test
+    public void testNullLocations() throws Exception {
+        assertNull(GeoGazetteerClient.parseLocations("null"));
+    }
+}

Reply via email to