- package cactusServer.utils;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- 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;
-
- /**
- * 多分使用しなくなると思う
- * @author student
- *
- */
- //@Provider
- //@Consumes(MediaType.APPLICATION_JSON)
- public class JSONConsumer implements MessageBodyReader<Object> {
- @Override
- public boolean isReadable(Class<?> type, java.lang.reflect.Type genericType,
- java.lang.annotation.Annotation[] annotations, MediaType mediaType) {
- // return true;
- return mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
- }
-
- @Override
- public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
- MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
- throws IOException, WebApplicationException {
- try {
- // return JSON.decode(entityStream,genericType);
- return JSON.decode(entityStream, type);
- } catch (JSONException e) {
- return null;
- }
- }
- }