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

io.castle.client.internal.json.CastleHeadersDeserializer Maven / Gradle / Ivy

Go to download

Castle adds real-time monitoring of your authentication stack, instantly notifying you and your users on potential account hijacks.

There is a newer version: 2.4.2
Show newest version
package io.castle.client.internal.json;

import com.google.common.collect.ImmutableList;
import com.google.gson.*;
import io.castle.client.model.CastleHeader;
import io.castle.client.model.CastleHeaders;

import java.lang.reflect.Type;
import java.util.Iterator;
import java.util.Set;

public class CastleHeadersDeserializer implements JsonDeserializer {
    @Override
    public CastleHeaders deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
        CastleHeaders headers = new CastleHeaders();
        ImmutableList.Builder builder = ImmutableList.builder();
        JsonObject root = json.getAsJsonObject();
        Set keys = root.keySet();
        for (Iterator iterator = keys.iterator(); iterator.hasNext(); ) {
            String key = iterator.next();
            JsonElement jsonElement = root.get(key);
            if (jsonElement.isJsonPrimitive()) {
                CastleHeader header = new CastleHeader();
                header.setKey(key);
                header.setValue(jsonElement.getAsString());
                builder.add(header);
            }
        }
        headers.setHeaders(builder.build());
        return headers;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy