public static MarshallerBuilder create() { return new MarshallerBuilder(); }
public static UnmarshallerBuilder create() { return new UnmarshallerBuilder(); }
public static void marshalWithNoValidation(Object object, OutputStream outputStream) { try { MarshallerBuilder.create() .withoutBeanValidation() .build() .marshal(object, outputStream); } catch (JAXBException ex) { throw new ConfigException(ex); } }
public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute(() -> { Marshaller marshaller = MarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); }
Config config = (Config) UnmarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build() .unmarshal(Files.newInputStream(Paths.get(configfile)));
public static void marshal(Object object, OutputStream outputStream) { try { MarshallerBuilder.create().build() .marshal(object, outputStream); } catch (Throwable ex) { Optional<ConstraintViolationException> validationException = unwrapConstraintViolationException(ex); if (validationException.isPresent()) { throw validationException.get(); } throw new ConfigException(ex); } }
public Marshaller build() { return JaxbCallback.execute(() -> { JAXBContext jAXBContext = JAXBContext.newInstance(JaxbUtil.JAXB_CLASSES); Marshaller marshaller = jAXBContext.createMarshaller(); if (!beanvalidation) { Enum enu = Enum.valueOf(Class.class.cast(marshaller .getProperty("eclipselink.beanvalidation.mode") .getClass()), "NONE"); marshaller.setProperty("eclipselink.beanvalidation.mode", enu); } marshaller.setProperty("eclipselink.media-type", mediaType.getValue()); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); if (mediaType == MediaType.JSON) { marshaller.setProperty("eclipselink.json.include-root", false); } return marshaller; }); }
public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute(() -> { Marshaller marshaller = MarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create() .withXmlMediaType() .withoutBeanValidation() .build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); }
public static void marshalWithNoValidation(Object object, OutputStream outputStream) { try { MarshallerBuilder.create() .withoutBeanValidation() .build() .marshal(object, outputStream); } catch (JAXBException ex) { throw new ConfigException(ex); } }
public static void marshal(Object object, OutputStream outputStream) { try { MarshallerBuilder.create().build() .marshal(object, outputStream); } catch (Throwable ex) { Optional<ConstraintViolationException> validationException = unwrapConstraintViolationException(ex); if (validationException.isPresent()) { throw validationException.get(); } throw new ConfigException(ex); } }
public Marshaller build() { return JaxbCallback.execute(() -> { JAXBContext jAXBContext = JAXBContext.newInstance(JaxbUtil.JAXB_CLASSES); Marshaller marshaller = jAXBContext.createMarshaller(); if (!beanvalidation) { Enum enu = Enum.valueOf(Class.class.cast(marshaller .getProperty("eclipselink.beanvalidation.mode") .getClass()), "NONE"); marshaller.setProperty("eclipselink.beanvalidation.mode", enu); } marshaller.setProperty("eclipselink.media-type", mediaType.getValue()); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); if (mediaType == MediaType.JSON) { marshaller.setProperty("eclipselink.json.include-root", false); } return marshaller; }); }
public static MarshallerBuilder create() { return new MarshallerBuilder(); }
public static UnmarshallerBuilder create() { return new UnmarshallerBuilder(); }
public Unmarshaller build() { return JaxbCallback.execute(() -> { JAXBContext jAXBContext = JAXBContext.newInstance(JaxbUtil.JAXB_CLASSES); Unmarshaller unmarshaller = jAXBContext.createUnmarshaller(); if (!beanvalidation) { Enum enu = Enum.valueOf(Class.class.cast(unmarshaller .getProperty("eclipselink.beanvalidation.mode") .getClass()), "NONE"); unmarshaller.setProperty("eclipselink.beanvalidation.mode", enu); } unmarshaller.setProperty("eclipselink.media-type", mediaType.getValue()); if (mediaType == MediaType.JSON) { unmarshaller.setProperty("eclipselink.json.include-root", false); } return unmarshaller; }); } }
public Unmarshaller build() { return JaxbCallback.execute(() -> { JAXBContext jAXBContext = JAXBContext.newInstance(JaxbUtil.JAXB_CLASSES); Unmarshaller unmarshaller = jAXBContext.createUnmarshaller(); if (!beanvalidation) { Enum enu = Enum.valueOf(Class.class.cast(unmarshaller .getProperty("eclipselink.beanvalidation.mode") .getClass()), "NONE"); unmarshaller.setProperty("eclipselink.beanvalidation.mode", enu); } unmarshaller.setProperty("eclipselink.media-type", mediaType.getValue()); if (mediaType == MediaType.JSON) { unmarshaller.setProperty("eclipselink.json.include-root", false); } return unmarshaller; }); } }