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

io.castle.client.internal.json.CastleMessageSerializer 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.3
Show newest version
package io.castle.client.internal.json;

import com.google.gson.JsonElement;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.Gson;

import io.castle.client.internal.utils.ContextMerge;
import io.castle.client.model.CastleMessage;

import java.lang.reflect.Type;
import java.util.HashMap;

public class CastleMessageSerializer implements JsonSerializer {

    private final Gson gson = CastleGsonModel.createGsonBuilder().create();

    @Override
    public JsonElement serialize(CastleMessage message, Type typeOfSrc, JsonSerializationContext context) {
        JsonElement root = gson.toJsonTree(message);
        HashMap other = message.getOther();
        if (other == null) {
            return root;
        }
        JsonElement otherJson = context.serialize(message.getOther());
        ContextMerge merger = new ContextMerge();
        return merger.merge(root.getAsJsonObject(), otherJson.getAsJsonObject());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy