Issue 524 - shorten __anonymous__ names for JSON importer
git-svn-id: http://google-refine.googlecode.com/svn/trunk@2432 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
254d4468cc
commit
fdac0c30cf
@ -62,6 +62,8 @@ import com.google.refine.util.JSONUtilities;
|
||||
public class JsonImporter extends TreeImportingParserBase {
|
||||
static final Logger logger = LoggerFactory.getLogger(JsonImporter.class);
|
||||
|
||||
public final static String ANONYMOUS = "_";
|
||||
|
||||
public JsonImporter() {
|
||||
super(false);
|
||||
}
|
||||
@ -258,13 +260,18 @@ public class JsonImporter extends TreeImportingParserBase {
|
||||
public String getFieldName() throws TreeReaderException {
|
||||
try {
|
||||
String text = parser.getCurrentName();
|
||||
|
||||
/*
|
||||
* If current token is a JsonToken.FIELD_NAME, this will be the
|
||||
* same as what getText() returns; for field values it will be
|
||||
* preceding field name; and for others (array values,
|
||||
* root-level values) null.
|
||||
*/
|
||||
//The following is a workaround for inconsistent Jackson JsonParser
|
||||
if(text == null){
|
||||
if(this.lastTokenWasAFieldNameAndCurrentTokenIsANewEntity) {
|
||||
text = this.lastFieldName;
|
||||
} else {
|
||||
text = "__anonymous__";
|
||||
text = ANONYMOUS;
|
||||
}
|
||||
}
|
||||
//end of workaround
|
||||
@ -308,7 +315,6 @@ public class JsonImporter extends TreeImportingParserBase {
|
||||
throw new TreeReaderException(e);
|
||||
}
|
||||
|
||||
// TODO just return null here?
|
||||
if(next == null) {
|
||||
throw new TreeReaderException("No more Json Tokens in stream");
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class JsonImporterTests extends ImporterTest {
|
||||
log(project);
|
||||
assertProjectCreated(project, 5, 6);
|
||||
|
||||
Assert.assertEquals( project.columnModel.getColumnByCellIndex(4).getName(), "__anonymous__ - genre");
|
||||
Assert.assertEquals( project.columnModel.getColumnByCellIndex(4).getName(), JsonImporter.ANONYMOUS + " - genre");
|
||||
|
||||
Row row0 = project.rows.get(0);
|
||||
Assert.assertNotNull(row0);
|
||||
@ -174,9 +174,9 @@ public class JsonImporterTests extends ImporterTest {
|
||||
JSONObject options = SUT.createParserUIInitializationData(
|
||||
job, new LinkedList<JSONObject>(), "text/json");
|
||||
JSONArray path = new JSONArray();
|
||||
JSONUtilities.append(path, "__anonymous__");
|
||||
JSONUtilities.append(path, JsonImporter.ANONYMOUS);
|
||||
JSONUtilities.append(path, "result");
|
||||
JSONUtilities.append(path, "__anonymous__");
|
||||
JSONUtilities.append(path, JsonImporter.ANONYMOUS);
|
||||
JSONUtilities.safePut(options, "recordPath", path);
|
||||
|
||||
RunTest(mqlOutput, options);
|
||||
@ -283,11 +283,11 @@ public class JsonImporterTests extends ImporterTest {
|
||||
}
|
||||
if(i == 4){
|
||||
Assert.assertEquals(token, Token.StartEntity);
|
||||
Assert.assertEquals(parser.getFieldName(), "__anonymous__");
|
||||
Assert.assertEquals(parser.getFieldName(), JsonImporter.ANONYMOUS);
|
||||
}
|
||||
if(i == 6){
|
||||
Assert.assertEquals(token, Token.StartEntity);
|
||||
Assert.assertEquals(parser.getFieldName(), "__anonymous__");
|
||||
Assert.assertEquals(parser.getFieldName(), JsonImporter.ANONYMOUS);
|
||||
}
|
||||
}
|
||||
}catch(Exception e){
|
||||
@ -334,8 +334,8 @@ public class JsonImporterTests extends ImporterTest {
|
||||
job, new LinkedList<JSONObject>(), "text/json");
|
||||
|
||||
JSONArray path = new JSONArray();
|
||||
JSONUtilities.append(path, "__anonymous__");
|
||||
JSONUtilities.append(path, "__anonymous__");
|
||||
JSONUtilities.append(path, JsonImporter.ANONYMOUS);
|
||||
JSONUtilities.append(path, JsonImporter.ANONYMOUS);
|
||||
|
||||
JSONUtilities.safePut(options, "recordPath", path);
|
||||
return options;
|
||||
|
@ -49,6 +49,7 @@ import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.importers.JsonImporter;
|
||||
import com.google.refine.importers.JsonImporter.JSONTreeReader;
|
||||
import com.google.refine.importers.XmlImporter.XmlParser;
|
||||
import com.google.refine.importers.tree.ImportColumn;
|
||||
@ -199,8 +200,8 @@ public class XmlImportUtilitiesTests extends RefineTest {
|
||||
new JSONTreeReader(new InputStreamReader(inputStream)));
|
||||
Assert.assertNotNull(path);
|
||||
Assert.assertEquals(path.length, 2);
|
||||
Assert.assertEquals(path[0], "__anonymous__");
|
||||
Assert.assertEquals(path[1], "__anonymous__");
|
||||
Assert.assertEquals(path[0], JsonImporter.ANONYMOUS);
|
||||
Assert.assertEquals(path[1], JsonImporter.ANONYMOUS);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user