Github user jackylk commented on a diff in the pull request: https://github.com/apache/carbondata/pull/1720#discussion_r158516073 --- Diff: core/src/main/java/org/apache/carbondata/core/metadata/datatype/DataTypes.java --- @@ -184,4 +224,60 @@ public static boolean isMapType(DataType dataType) { return dataType.getId() == MAP_TYPE_ID; } + /** + * This class is added to support backword compatibility with table info object, where DATATYPE + * is string in old version and OBJECT in new version + */ + public static class DataTypeAdapter extends TypeAdapter<Object> { + + private static DataTypeAdapter dataTypeAdapter = new DataTypeAdapter(); + + private DataTypeAdapter() { + } + + public static DataTypeAdapter getInstance() { + return dataTypeAdapter; + } + + @Override public void write(JsonWriter jsonWriter, Object o) throws IOException { + } + + @Override public Object read(JsonReader jsonReader) throws IOException { + DataType newObj; + JsonToken token = jsonReader.peek(); + + if (token == JsonToken.STRING) { + newObj = DataTypes.valueOf(jsonReader.nextString()); + } else { + jsonReader.beginObject(); + + int id = 0; + int precedenceOrder = 0; + String name = ""; + int sizeInBytes = 0; + + while (jsonReader.hasNext()) { + switch (jsonReader.nextName()) { + case "id": + id = jsonReader.nextInt(); + break; + case "precedenceOrder": + precedenceOrder = jsonReader.nextInt(); + break; + case "name": + name = jsonReader.nextString(); + break; + case "sizeInBytes": + sizeInBytes = jsonReader.nextInt(); + break; + default: + break; --- End diff -- I think we should throw IOException here
---