public void writeTo(Object entry, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException
{
JAXBContextFinder finder = getFinder(mediaType);
if (finder == null)
{
throw new JAXBMarshalException("Unable to find JAXBContext for media type: " + mediaType);
}
Class baseType = Types.getCollectionBaseType(type, genericType);
entityStream.write('[');
try
{
JAXBContext ctx = finder.findCachedContext(baseType, mediaType, annotations);
Marshaller marshaller = ctx.createMarshaller();
marshaller = AbstractJAXBProvider.decorateMarshaller(baseType, annotations, mediaType, marshaller);
if (type.isArray())
{
Object[] array = (Object[]) entry;
boolean first = true;
for (Object obj : array)
{
if (first)
{
first = false;
}
else
{
entityStream.write(',');
}
marshaller.marshal(obj, entityStream);
}
}
else
{
Collection collection = (Collection) entry;
boolean first = true;
for (Object obj : collection)
{
if (first)
{
first = false;
}
else
{
entityStream.write(',');
}
marshaller.marshal(obj, entityStream);
}
}
entityStream.write(']');
}
catch (JAXBException e)
{
throw new JAXBMarshalException(e);
}
}