Newer
Older
CactusServer / src / main / java / cactusServer / utils / JSONConsumer.java
  1. package cactusServer.utils;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.lang.annotation.Annotation;
  7. import java.lang.reflect.Type;
  8.  
  9. import javax.validation.constraints.Null;
  10. import javax.ws.rs.Consumes;
  11. import javax.ws.rs.WebApplicationException;
  12. import javax.ws.rs.core.MediaType;
  13. import javax.ws.rs.core.MultivaluedMap;
  14. import javax.ws.rs.ext.MessageBodyReader;
  15. import javax.ws.rs.ext.Provider;
  16.  
  17. import net.arnx.jsonic.JSON;
  18. import net.arnx.jsonic.JSONException;
  19.  
  20. /**
  21. * 多分使用しなくなると思う
  22. * @author student
  23. *
  24. */
  25. //@Provider
  26. //@Consumes(MediaType.APPLICATION_JSON)
  27. public class JSONConsumer implements MessageBodyReader<Object> {
  28. @Override
  29. public boolean isReadable(Class<?> type, java.lang.reflect.Type genericType,
  30. java.lang.annotation.Annotation[] annotations, MediaType mediaType) {
  31. // return true;
  32. return mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE);
  33. }
  34.  
  35. @Override
  36. public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
  37. MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
  38. throws IOException, WebApplicationException {
  39. try {
  40. // return JSON.decode(entityStream,genericType);
  41. return JSON.decode(entityStream, type);
  42. } catch (JSONException e) {
  43. return null;
  44. }
  45. }
  46. }