diff --git a/src/main/java/cactusServer/utils/JSONConsumer.java b/src/main/java/cactusServer/utils/JSONConsumer.java new file mode 100644 index 0000000..a3412db --- /dev/null +++ b/src/main/java/cactusServer/utils/JSONConsumer.java @@ -0,0 +1,46 @@ +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; + +/** + * �����g�p���Ȃ��Ȃ�Ǝv�� -> �S�~ + * @author student + * + */ +//@Provider +//@Consumes(MediaType.APPLICATION_JSON) +public class JSONConsumer implements MessageBodyReader { + @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 type, Type genericType, Annotation[] annotations, MediaType mediaType, + MultivaluedMap httpHeaders, InputStream entityStream) + throws IOException, WebApplicationException { + try { + // return JSON.decode(entityStream, genericType); + return JSON.decode(entityStream, type); + } catch (JSONException e) { + return null; + } + } +}