private static void serializeTypeWithGenericSerialization()

in fluss-common/src/main/java/com/alibaba/fluss/utils/json/DataTypeJsonSerde.java [88:148]


    private static void serializeTypeWithGenericSerialization(
            DataType dataType, JsonGenerator jsonGenerator) throws IOException {
        jsonGenerator.writeStartObject();

        jsonGenerator.writeStringField(FIELD_NAME_TYPE_NAME, dataType.getTypeRoot().name());
        if (!dataType.isNullable()) {
            jsonGenerator.writeBooleanField(FIELD_NAME_NULLABLE, false);
        }

        switch (dataType.getTypeRoot()) {
            case BOOLEAN:
            case TINYINT:
            case SMALLINT:
            case INTEGER:
            case BIGINT:
            case FLOAT:
            case DOUBLE:
            case DATE:
            case BYTES:
            case STRING:
                // do nothing.
                break;
            case CHAR:
            case BINARY:
                jsonGenerator.writeNumberField(FIELD_NAME_LENGTH, getLength(dataType));
                break;
            case DECIMAL:
                final DecimalType decimalType = (DecimalType) dataType;
                serializeDecimal(decimalType.getPrecision(), decimalType.getScale(), jsonGenerator);
                break;
            case TIME_WITHOUT_TIME_ZONE:
                final TimeType timeType = (TimeType) dataType;
                jsonGenerator.writeNumberField(FIELD_NAME_PRECISION, timeType.getPrecision());
                break;
            case TIMESTAMP_WITHOUT_TIME_ZONE:
                final TimestampType timestampType = (TimestampType) dataType;
                serializeTimestamp(timestampType.getPrecision(), jsonGenerator);
                break;
            case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
                final LocalZonedTimestampType localZonedTimestampType =
                        (LocalZonedTimestampType) dataType;
                serializeTimestamp(localZonedTimestampType.getPrecision(), jsonGenerator);
                break;
            case ARRAY:
                serializeCollection(((ArrayType) dataType).getElementType(), jsonGenerator);
                break;
            case MAP:
                serializeMap((MapType) dataType, jsonGenerator);
                break;
            case ROW:
                serializeRow((RowType) dataType, jsonGenerator);
                break;
            default:
                throw new UnsupportedOperationException(
                        String.format(
                                "Unable to serialize logical type '%s'. Please check the documentation for supported types.",
                                dataType.asSummaryString()));
        }

        jsonGenerator.writeEndObject();
    }