@Test public void testWriteArrayNull() throws Exception { JsonXML config = JsonXMLDefault.class.getAnnotation(JsonXML.class); StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(SampleType.class); new JsonXMLBinder().writeArray(SampleType.class, config, context, writer, null); Assert.assertEquals("null", writer.toString()); }
public void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamWriter writer = createXMLStreamWriter(type, config, stream); if (collection == null) { writer.writeCharacters(null); } else { Marshaller marshaller = context.createMarshaller(); if (!writeDocumentArray) { writer.writeStartDocument(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); } writer.writeProcessingInstruction(JsonXMLStreamConstants.MULTIPLE_PI_TARGET); for (Object value : collection) { if (value == null) { writer.writeCharacters(null); } else { marshal(type, config, marshaller, writer, value); } } if (!writeDocumentArray) { writer.writeEndDocument(); } } writer.close(); }
JsonXMLBinder { public void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamWriter writer = createXMLStreamWriter(type, config, stream); if (collection == null) { writer.writeCharacters(null); } else { Marshaller marshaller = context.createMarshaller(); if (!writeDocumentArray) { writer.writeStartDocument(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); } writer.writeProcessingInstruction(JsonXMLStreamConstants.MULTIPLE_PI_TARGET); for (Object value : collection) { if (value == null) { writer.writeCharacters(null); } else { marshal(type, config, marshaller, writer, value); } } if (!writeDocumentArray) { writer.writeEndDocument(); } } writer.close(); } }
JsonXMLBinder { public void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamWriter writer = createXMLStreamWriter(type, config, stream); if (collection == null) { writer.writeCharacters(null); } else { Marshaller marshaller = context.createMarshaller(); if (!writeDocumentArray) { writer.writeStartDocument(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); } writer.writeProcessingInstruction(JsonXMLStreamConstants.MULTIPLE_PI_TARGET); for (Object value : collection) { if (value == null) { writer.writeCharacters(null); } else { marshal(type, config, marshaller, writer, value); } } if (!writeDocumentArray) { writer.writeEndDocument(); } } writer.close(); } JsonXMLBinder(); protected  JsonXMLBinder(boolean writeDocumentArray); protected  JsonXMLBinder(JsonXMLRootProvider rootProvider, boolean writeDocumentArray); }
JsonXMLBinder { public void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamWriter writer = createXMLStreamWriter(type, config, stream); if (collection == null) { writer.writeCharacters(null); } else { Marshaller marshaller = context.createMarshaller(); if (!writeDocumentArray) { writer.writeStartDocument(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); } writer.writeProcessingInstruction(JsonXMLStreamConstants.MULTIPLE_PI_TARGET); for (Object value : collection) { if (value == null) { writer.writeCharacters(null); } else { marshal(type, config, marshaller, writer, value); } } if (!writeDocumentArray) { writer.writeEndDocument(); } } writer.close(); } JsonXMLBinder(); protected  JsonXMLBinder(boolean writeDocumentArray); protected  JsonXMLBinder(JsonXMLRootProvider rootProvider, boolean writeDocumentArray); boolean isBindable(Class<?> type); T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream); void writeObject(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Object value); List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream); void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection); }
JsonXMLBinder { public void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamWriter writer = createXMLStreamWriter(type, config, stream); if (collection == null) { writer.writeCharacters(null); } else { Marshaller marshaller = context.createMarshaller(); if (!writeDocumentArray) { writer.writeStartDocument(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); } writer.writeProcessingInstruction(JsonXMLStreamConstants.MULTIPLE_PI_TARGET); for (Object value : collection) { if (value == null) { writer.writeCharacters(null); } else { marshal(type, config, marshaller, writer, value); } } if (!writeDocumentArray) { writer.writeEndDocument(); } } writer.close(); } JsonXMLBinder(); protected  JsonXMLBinder(boolean writeDocumentArray); protected  JsonXMLBinder(JsonXMLRootProvider rootProvider, boolean writeDocumentArray); boolean isBindable(Class<?> type); T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream); void writeObject(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Object value); List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream); void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection);  }