Skip to content

Instantly share code, notes, and snippets.

@miere
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miere/c2da3e8783e7db176097 to your computer and use it in GitHub Desktop.
Save miere/c2da3e8783e7db176097 to your computer and use it in GitHub Desktop.
package sample;
import io.undertow.server.HttpServerExchange;
import java.io.IOException;
import java.io.Reader;
import java.nio.channels.Channels;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JSONConverver {
final ObjectMapper mapper = new ObjectMapper();
public <T> T convert(
final HttpServerExchange exchange, final Class<T> targetClass ) throw IOException {
return convert( exchange, targetClass, "UTF-8" );
}
public <T> T convert(
final HttpServerExchange exchange, final Class<T> targetClass,
final String contentEncoding ) throw IOException {
final Reader reader = Channels.newReader( exchange.getRequestChannel(), contentEncoding );
return mapper.readValue(input, targetClass);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment