Merge pull request #1523 from OpenRefine/issue/1517

fix issue #1517, limit is written as int and should have been read as int
This commit is contained in:
Jacky 2018-02-28 19:41:44 -05:00 committed by GitHub
commit 8dfd7588a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -112,8 +112,7 @@ public class StandardReconConfig extends ReconConfig {
JSONObject t = obj.has("type") && !obj.isNull("type") ? obj.getJSONObject("type") : null; 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 = obj.has("limit") && !obj.isNull("limit") ? obj.getInt("limit") : 0;
int limit = "".equals(limitString) ? 0 : Integer.parseInt(limitString);
return new StandardReconConfig( return new StandardReconConfig(
obj.getString("service"), obj.getString("service"),

View File

@ -2,11 +2,13 @@ package com.google.refine.tests.model;
import java.util.ArrayList; import java.util.ArrayList;
import org.json.JSONObject;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.refine.model.recon.ReconConfig;
import com.google.refine.model.recon.StandardReconConfig; import com.google.refine.model.recon.StandardReconConfig;
import com.google.refine.tests.RefineTest; import com.google.refine.tests.RefineTest;
@ -44,4 +46,32 @@ public class ReconTests extends RefineTest {
Assert.assertTrue(!Double.isInfinite(r)); Assert.assertTrue(!Double.isInfinite(r));
Assert.assertTrue(!Double.isNaN(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);
}
} }