package cactusServer.utils;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.validation.constraints.Null;
import javax.ws.rs.Consumes;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.Provider;
import net.arnx.jsonic.JSON;
import net.arnx.jsonic.JSONException;
@Provider
@Consumes(MediaType.APPLICATION_JSON)
public class JSONConsumer implements MessageBodyReader {
public boolean isReadable(java.lang.Class type,
java.lang.reflect.Type genericType, java.lang.annotation.Annotation[]
annotations, MediaType mediaType) {
return true;
}
@Override
public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
// TODO Auto-generated method stub
try {
return JSON.decode(entityStream,genericType);
} catch (JSONException e) {
// TODO Auto-generated catch block
return null;
} catch (IOException e) {
// TODO Auto-generated catch block
return null;
}
}
}