io.joshworks.restclient.http.mapper.JsonMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unirest-java Show documentation
Show all versions of unirest-java Show documentation
Rest Java client based on Unirest
package io.joshworks.restclient.http.mapper;
import com.google.gson.Gson;
import io.joshworks.restclient.http.exceptions.JsonParsingException;
/**
* Created by Josh Gontijo on 5/5/17.
*/
public class JsonMapper implements ObjectMapper {
private final Gson gson = new Gson();
@Override
public T readValue(String value, Class valueType) {
try {
return gson.fromJson(value, valueType);
} catch (Exception e) {
throw new JsonParsingException("Failed to parse " + value, e);
}
}
@Override
public String writeValue(Object value) {
try {
return gson.toJson(value);
} catch (Exception e) {
throw new JsonParsingException("Failed to create json of " + value, e);
}
}
}