package de.anycook.api.providers.messagebodywriters; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.ext.MessageBodyWriter; import javax.ws.rs.ext.Provider; import java.io.IOException; import java.io.OutputStream; import java.lang.annotation.Annotation; import java.lang.reflect.Type; /** * @author Jan Graßegger<jan@anycook.de> */ @Provider @Produces({"text/plain", "application/json"}) public class IntegerMessageBodyWriter implements MessageBodyWriter<Integer>{ @Override public boolean isWriteable(Class<?> type, Type type1, Annotation[] antns, MediaType mt) { return true; } @Override public long getSize(Integer t, Class<?> type, Type type1, Annotation[] antns, MediaType mt) { return -1; } @Override public void writeTo(Integer integer, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(integer.toString().getBytes()); } }