@Test public void testMarshal() throws JAXBException { String xml = MarshalHelper.marshal(car); assertTrue(xml.contains("<?xml")); assertTrue(xml.contains("ABC-123")); assertTrue(xml.contains("Passat")); assertTrue(xml.contains("Volkswagen")); }
public static String marshal(Car car) throws JAXBException { StringWriter stringWriter = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(Car.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); QName qName = new QName("info.source4code.jaxb.model", "car"); JAXBElement<Car> root = new JAXBElement<Car>(qName, Car.class, car); jaxbMarshaller.marshal(root, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; }
MarshalHelper { public static String marshal(Car car) throws JAXBException { StringWriter stringWriter = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(Car.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); QName qName = new QName("info.source4code.jaxb.model", "car"); JAXBElement<Car> root = new JAXBElement<Car>(qName, Car.class, car); jaxbMarshaller.marshal(root, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; } }
MarshalHelper { public static String marshal(Car car) throws JAXBException { StringWriter stringWriter = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(Car.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); QName qName = new QName("info.source4code.jaxb.model", "car"); JAXBElement<Car> root = new JAXBElement<Car>(qName, Car.class, car); jaxbMarshaller.marshal(root, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; } private  MarshalHelper(); }
MarshalHelper { public static String marshal(Car car) throws JAXBException { StringWriter stringWriter = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(Car.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); QName qName = new QName("info.source4code.jaxb.model", "car"); JAXBElement<Car> root = new JAXBElement<Car>(qName, Car.class, car); jaxbMarshaller.marshal(root, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; } private  MarshalHelper(); static String marshalError(Car car); static String marshal(Car car); }
MarshalHelper { public static String marshal(Car car) throws JAXBException { StringWriter stringWriter = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(Car.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); QName qName = new QName("info.source4code.jaxb.model", "car"); JAXBElement<Car> root = new JAXBElement<Car>(qName, Car.class, car); jaxbMarshaller.marshal(root, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; } private  MarshalHelper(); static String marshalError(Car car); static String marshal(Car car);  }