Bug in org.knime.js.core.JSONDataTableSpec

Hi everyone,

I am creating a JS KNIME node and found out this bug when trying to deserialize a table from JSON. My custom node is similar to the Javascript Table View but  is deserializing the table as well.

When serializing, the JSONDataTableSpec constructor in the line 195 is saving the names of the column types (not the actual enum values).

if (!Arrays.asList(excludeColumns).contains(colName)) {
    colNames.add(colName);
    orgTypes.add(spec.getColumnSpec(i).getType().getName());
    DataType colType = spec.getColumnSpec(i).getType();
    colTypes.add(getJSONType(colType).name);
    numColumns++;
}

Yet later when I tried to deserialize the JSONDataTable to a regular BufferedDataTable with the method JSONDataTable#createBufferedDataTable, the JSONDataTableSpec#createDataTableSpec in the line 215 is trying to get the enum values from the name properties of the enum JSTypes instead of the actual string representation.

for (int i = 0; i < m_numColumns; i++) {
    JSTypes type = JSTypes.valueOf(m_colTypes.get(i));
    DataType dataType = null;
    switch (type) {
         case BOOLEAN:

The JSTypes enum is using uppercase for its values and lowercase for its name property. For example I cannot access with a "boolean" column type a column of type JSType.BOOLEAN. The valueOf is failing here.

        BOOLEAN("boolean"),
        NUMBER("number"),
        STRING("string"),
        /** @since 2.10 */
        PNG("png"),
        /** @since 2.10 */
        SVG("svg"),
        /** @since 2.11 */
        DATE_TIME("dateTime"),
        UNDEFINED("undefined");

As a result deserializing a toy table with string columns produces this exception.

ERROR JavaScript Editable Table 0:77       Execute failed: No enum constant org.knime.js.core.JSONDataTableSpec.JSTypes.string

Best regards and happy coding,

Miguel

Hi all,

Since I need this node I decided to fix the JSON classes myself. First I copied the JSONDataTableSpec and JSONDataTable classes to my project and changed the following line in the JSONDataTableSpec constructor (the big one):

colTypes.add(getJSONType(colType).name);

with

colTypes.add(getJSONType(colType).name());

Now the call to JSTypes.valueOf in JSONDataTable#createBufferedDataTable works and the table can be deserialized.

By the way, there was another bug in the createBufferedDataTable method. The container used to generate the table was not closed, so I had to close it before returning the table. Added line is highlighted.

        DataRow newRow = new DefaultRow(row.getRowKey(), dataCells);
        container.addRowToTable(newRow);
    }
    container.close();
    return container.getTable();
}

Best,

Miguel

 

Hi Miguel,

thank you very much for finding and reporting this bug. I will have a look at it later this week and push it into the next bugfix release.

Regards,

Christian