JaxbHelper.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:artifactory 作者:
public void write(OutputStream stream, T object) {
    try {
        JAXBContext context = JAXBContext.newInstance(object.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        XmlSchema schemaAnnotation = object.getClass().getPackage().getAnnotation(XmlSchema.class);
        if (schemaAnnotation != null && schemaAnnotation.location() != null) {
            marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaAnnotation.location());
            // TODO: May just this ArtifactoryConfigVersion.getCurrent().getXsdLocation());
        }
        marshaller.marshal(object, stream);
    } catch (Exception e) {
        throw new RuntimeException("Failed to write object to stream.", e);
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号