List of usage examples for javax.xml.bind.helpers DefaultValidationEventHandler DefaultValidationEventHandler
DefaultValidationEventHandler
From source file:Main.java
public static <T> T deserialize(Class<T> res, InputStream is) throws JAXBException { Unmarshaller u = CTX.createUnmarshaller(); u.setEventHandler(new DefaultValidationEventHandler()); return res.cast(u.unmarshal(is)); }
From source file:Main.java
public static void serialize(Object o, OutputStream os, Boolean format) throws JAXBException { Marshaller m = CTX.createMarshaller(); m.setEventHandler(new DefaultValidationEventHandler()); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format); m.marshal(o, os);//from w w w .ja v a 2s . com }
From source file:Main.java
public static <T> T deserialize(Class<T> res, InputStream is) throws JAXBException { String pkg = res.getPackage().getName(); JAXBContext jc = getCachedContext(pkg); Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new DefaultValidationEventHandler()); return res.cast(u.unmarshal(is)); }
From source file:Main.java
public static void serialize(Object o, OutputStream os, Boolean format) throws JAXBException { String pkg = o.getClass().getPackage().getName(); JAXBContext jc = getCachedContext(pkg); Marshaller m = jc.createMarshaller(); m.setEventHandler(new DefaultValidationEventHandler()); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.marshal(o, os);/*from w ww.j ava2s .c om*/ }
From source file:ddf.catalog.transformer.xml.XmlInputTransformer.java
private Metacard testXform(InputStream input, String id) throws IOException, CatalogTransformerException { ParserConfigurator parserConfigurator = getParserConfigurator() .setAdapter(new MetacardTypeAdapter(metacardTypes)).setHandler(new DefaultValidationEventHandler()); try {//from ww w . j a v a 2 s . c om Metacard metacard = getParser().unmarshal(parserConfigurator, Metacard.class, input); if (metacard == null) { throw new CatalogTransformerException(FAILED_TRANSFORMATION); } if (!StringUtils.isEmpty(id)) { metacard.setAttribute(new AttributeImpl(Metacard.ID, id)); } return metacard; } catch (ParserException e) { LOGGER.error("Error parsing metacard", e); throw new CatalogTransformerException(FAILED_TRANSFORMATION, e); } }
From source file:org.sonatype.nexus.plugins.crowd.client.rest.RestClient.java
private <T> T unmarshal(HttpResponse response, Class<T> type) throws JAXBException, IOException { JAXBContext jaxbC = JAXBContext.newInstance(type); Unmarshaller um = jaxbC.createUnmarshaller(); um.setEventHandler(new DefaultValidationEventHandler()); return um.unmarshal(new StreamSource(response.getEntity().getContent()), type).getValue(); }