@Override public String marshalToJSON(Object obj) throws MarshalException, UnsupportedMediaTypeException { String result = null; try { Method method = findCreateMethod(obj); if (method != null) { JAXBElement<?> element = (JAXBElement<?>) method.invoke(objFactory, obj); if (element != null) { result = JAXBUtils.marshalToJSON(element); } } } catch (Exception e) { logger.error("An error occurred marshalling object to JSON", e); throw new MarshalException("An error occurred marshalling object to JSON", e); } return result; }