class MessageSerializer {

    @SuppressWarnings("unchecked")
    public static <E extends Message> E deserialize(String msg) {
        try {
            Map<String, Object> m = objectMapper.readValue(msg, Map.class);
            String messageType = (String) m.get("messageType");
            if (messageType == null) {
                throw new IllegalStateException("messageType not found: " + m);
            }
            return (E) objectMapper.convertValue(m, MessageType.valueOf(messageType).getClazz());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private  MessageSerializer();

}