From ab26bf4a273ed2c4c3664579875725a9b509f06d Mon Sep 17 00:00:00 2001 From: Jacky Date: Sun, 25 Feb 2018 17:22:34 -0500 Subject: [PATCH] fix issue #1517, limit is writen as int and should have been read as int --- .../model/recon/StandardReconConfig.java | 3 +- .../google/refine/tests/model/ReconTests.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/main/src/com/google/refine/model/recon/StandardReconConfig.java b/main/src/com/google/refine/model/recon/StandardReconConfig.java index 0c7f5ea7b..f1cb97d3b 100644 --- a/main/src/com/google/refine/model/recon/StandardReconConfig.java +++ b/main/src/com/google/refine/model/recon/StandardReconConfig.java @@ -112,8 +112,7 @@ public class StandardReconConfig extends ReconConfig { JSONObject t = obj.has("type") && !obj.isNull("type") ? obj.getJSONObject("type") : null; - String limitString = obj.has("limit") && !obj.isNull("limit") ? obj.getString("limit") : ""; - int limit = "".equals(limitString) ? 0 : Integer.parseInt(limitString); + int limit = obj.has("limit") && !obj.isNull("limit") ? obj.getInt("limit") : 0; return new StandardReconConfig( obj.getString("service"), diff --git a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java b/main/tests/server/src/com/google/refine/tests/model/ReconTests.java index 0b4a04411..5d6466c99 100644 --- a/main/tests/server/src/com/google/refine/tests/model/ReconTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/ReconTests.java @@ -2,11 +2,13 @@ package com.google.refine.tests.model; import java.util.ArrayList; +import org.json.JSONObject; import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.refine.model.recon.ReconConfig; import com.google.refine.model.recon.StandardReconConfig; import com.google.refine.tests.RefineTest; @@ -44,4 +46,32 @@ public class ReconTests extends RefineTest { Assert.assertTrue(!Double.isInfinite(r)); Assert.assertTrue(!Double.isNaN(r)); } + + /** + * Regression for issue #1517: + * JSON deserialization exception due to the upgrade of org.json library in data package PR + * @throws Exception + */ + @Test + public void limitJSONKeyTest() throws Exception { + JSONObject obj = new JSONObject( + " {\n" + + " \"mode\": \"standard-service\",\n" + + " \"service\": \"https://tools.wmflabs.org/openrefine-wikidata/en/api\",\n" + + " \"identifierSpace\": \"http://www.wikidata.org/entity/\",\n" + + " \"schemaSpace\": \"http://www.wikidata.org/prop/direct/\",\n" + + " \"type\": {\n" + + " \"id\": \"Q13442814\",\n" + + " \"name\": \"scientific article\"\n" + + " },\n" + + " \"autoMatch\": true,\n" + + " \"columnDetails\": [],\n" + + " \"limit\": 0\n" + + " }"); + + ReconConfig config = StandardReconConfig.reconstruct(obj); + + // Assert the object is created + Assert.assertTrue(config != null); + } }