public static <T> T valueOf(String sessionStr, Class tClass) { try { Unmarshaller unmarshaller = getLensJAXBContext(tClass).createUnmarshaller(); Object ret = unmarshaller.unmarshal(new StringReader(sessionStr)); if (ret instanceof JAXBElement) { return ((JAXBElement<T>) ret).getValue(); } return (T) ret; } catch (JAXBException e) { return null; } }
public static <T> T valueOf(String sessionStr, Class tClass) { try { Unmarshaller unmarshaller = getLensJAXBContext(tClass).createUnmarshaller(); Object ret = unmarshaller.unmarshal(new StringReader(sessionStr)); if (ret instanceof JAXBElement) { return ((JAXBElement<T>) ret).getValue(); } return (T) ret; } catch (JAXBException e) { return null; } }
public static String toString(Object o) { if (!(o instanceof JAXBElement) && o.getClass().getAnnotation(XmlRootElement.class) == null && o.getClass().getAnnotation(XmlType.class)!= null) { o = new JAXBElement(new QName("uri:lens:cube:0.1", o.getClass().getAnnotation(XmlType.class).name()), o.getClass(), null, o); } try { StringWriter stringWriter = new StringWriter(); Class cl = null; if (o instanceof JAXBElement) { cl = ((JAXBElement) o).getDeclaredType(); } else { cl = o.getClass(); } Marshaller marshaller = getLensJAXBContext(cl).createMarshaller(); marshaller.marshal(o, stringWriter); return stringWriter.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } }
public static String toString(Object o) { if (!(o instanceof JAXBElement) && o.getClass().getAnnotation(XmlRootElement.class) == null && o.getClass().getAnnotation(XmlType.class)!= null) { o = new JAXBElement(new QName("uri:lens:cube:0.1", o.getClass().getAnnotation(XmlType.class).name()), o.getClass(), null, o); } try { StringWriter stringWriter = new StringWriter(); Class cl = null; if (o instanceof JAXBElement) { cl = ((JAXBElement) o).getDeclaredType(); } else { cl = o.getClass(); } Marshaller marshaller = getLensJAXBContext(cl).createMarshaller(); marshaller.marshal(o, stringWriter); return stringWriter.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } }