edu.ksu.canvas.impl.GsonResponseParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of canvas-api Show documentation
Show all versions of canvas-api Show documentation
A native Java library to talk to the Canvas REST API
package edu.ksu.canvas.impl;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken;
import edu.ksu.canvas.interfaces.ResponseParser;
import edu.ksu.canvas.net.Response;
import java.lang.reflect.Type;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.Date;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
public class GsonResponseParser implements ResponseParser {
private static final Logger LOG = Logger.getLogger(GsonResponseParser.class);
@Override
public List parseToList(Type type, Response response) {
Gson gson = getDefaultGsonParser(false);
return gson.fromJson(response.getContent(), type);
}
@Override
public Optional parseToObject(Class clazz, Response response) {
Gson gson = getDefaultGsonParser(false);
return Optional.of(gson.fromJson(response.getContent(), clazz));
}
@Override
public Map parseToMap(Class clazz, Response response) {
Gson gson = getDefaultGsonParser(false);
Type mapType = new TypeToken