com.amazon.SellingPartnerAPIAA.LWAClientScopesSerializerDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sellingpartnerapi-aa-java Show documentation
Show all versions of sellingpartnerapi-aa-java Show documentation
A build of Amazon sellingpartnerapi-aa-java client
The newest version!
package com.amazon.SellingPartnerAPIAA;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class LWAClientScopesSerializerDeserializer implements JsonDeserializer,
JsonSerializer {
@Override
public JsonElement serialize(LWAClientScopes src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(String.join(" ", src.getScopes()));
}
@Override
public LWAClientScopes deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext jsonDeserializationContext)
throws JsonParseException {
JsonObject jsonObj = jsonElement.getAsJsonObject();
Set scopeSet = new HashSet<>(Arrays.asList(jsonObj.get("scope").getAsString().split(" ")));
return new LWAClientScopes(scopeSet);
}
}