In my example JAXBContext.newInstance(T) need paramether Class and this solution with generics not works.
public class SerializationUtilJaxb<T> {
public String serialize(T jaxbObject) {
StringWriter stringWriter = new StringWriter();
try {
JAXBContext jaxbContext = JAXBContext.newInstance(T);
Marshaller objectMarshaller = jaxbContext.createMarshaller();
objectMarshaller.marshal(jaxbObject, stringWriter);
return stringWriter.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
}
Can I ask why? And what is correct solution with generics?