fix issue #1517, limit is writen as int and should have been read as int

This commit is contained in:
Jacky 2018-02-25 17:22:34 -05:00
parent b51dbdcbf2
commit ab26bf4a27
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;
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"),

View File

@ -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);
}
}