Last active
August 29, 2015 14:05
-
-
Save miere/c2da3e8783e7db176097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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