@Test public void testMarshalError() throws JAXBException { try { MarshalHelper.marshalError(car); fail("no exception thrown"); } catch (MarshalException e) { logger.error("MarshalException", e); assertTrue(e.toString().contains( "is missing an @XmlRootElement annotation")); } }
public static String marshalError(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); jaxbMarshaller.marshal(car, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; }
MarshalHelper { public static String marshalError(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); jaxbMarshaller.marshal(car, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; } }
MarshalHelper { public static String marshalError(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); jaxbMarshaller.marshal(car, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; } private  MarshalHelper(); }
MarshalHelper { public static String marshalError(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); jaxbMarshaller.marshal(car, 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 marshalError(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); jaxbMarshaller.marshal(car, stringWriter); String result = stringWriter.toString(); LOGGER.info(result); return result; } private  MarshalHelper(); static String marshalError(Car car); static String marshal(Car car);  }