@SuppressWarnings("unchecked") private <S extends Score<?>> S marshallUnmarshallScore(S toBeMarshalled) { ScoreWrapper wrapper = new ScoreWrapper(toBeMarshalled); SolverInstance instance = new SolverInstance(); instance.setScoreWrapper(wrapper); String marshalledSolver = marshaller.marshall(instance); SolverInstance result = marshaller.unmarshall(marshalledSolver, SolverInstance.class); return (S) result.getScoreWrapper().toScore(); } }