How to change editorComponent based on item type

Hello,
I have column with an object that accepts string, boolean and so on values.
I would like after double click on a row to edit this values in
in the appropriate field, and so the edit field to change based on the data type, so for boolean i want checkbox, textfield for string…

I tried something like this…
grid.addItemDoubleClickListener(event → {
if(event.getItem().getType().equals(ColumnType.String)) {
binder.bind(valueField, “value”);
valueColumn.setEditorComponent(valueField); // valueField = new TextField()
grid.getEditor().editItem(event.getItem());
}
});

But this doesnt seem to work good, for example data type is String and editor component is being set to textField but i get error java.lang.String cannot be cast to java.lang.Boolean… as if the editorcomponent has not been set correctly and remembers the previous setting for boolean values