All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazon.SellingPartnerAPIAA.LWAClientScopesSerializerDeserializer Maven / Gradle / Ivy

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);

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy