public static <T> T parse(@NotNull String data, @NotNull Class<T> type) throws JAXBException {
    if (!cachedContexts.containsKey(type)) {
      cachedContexts.put(type, JAXBContext.newInstance(type));
    }
    JAXBContext context = cachedContexts.get(type);
    Unmarshaller unmarshaller = context.createUnmarshaller();

    unmarshaller.setEventHandler(new ValidationEventHandler() {
      @Override
      public boolean handleEvent(@NotNull ValidationEvent event) {
        // Fail on exceptions, but not on other errors like "unexpected element" as sometimes we do not use all provided xml data.
        return event.getLinkedException() == null;
      }
    });
    //noinspection unchecked
    return (T)unmarshaller.unmarshal(new StringReader(data.trim()));
  }
public static <T> T parse(@NotNull String data, @NotNull Class<T> type)