All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.redpipe.engine.resteasy.JsonObjectBodyReader Maven / Gradle / Ivy

package net.redpipe.engine.resteasy;

import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

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 org.apache.commons.io.IOUtils;

import io.vertx.core.json.JsonObject;

@Provider
public class JsonObjectBodyReader implements MessageBodyReader{

	@Override
	public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) {
		return type == JsonObject.class;
	}

	@Override
	public JsonObject readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType,
			MultivaluedMap httpHeaders, InputStream entityStream)
			throws IOException, WebApplicationException {
		byte[] byteArray = IOUtils.toByteArray(entityStream);
		// FIXME: encoding
		return new JsonObject(new String(byteArray, "utf-8"));
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy