
org.johnnei.enjin.internal.gson.RequestWrapperSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enjin-api-impl Show documentation
Show all versions of enjin-api-impl Show documentation
The specification of the Enjin API
The newest version!
package org.johnnei.enjin.internal.gson;
import java.lang.reflect.Type;
import java.util.Map.Entry;
import org.johnnei.enjin.internal.EnjinWrapper;
import org.johnnei.enjin.internal.RequestWrapper;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
public class RequestWrapperSerializer implements JsonSerializer> {
@Override
public JsonElement serialize(RequestWrapper> src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject request = (JsonObject) context.serialize(src, EnjinWrapper.class);
request.add("params", context.serialize(src.getParams()));
if (src.getAuthToken() != null) {
// Merge auth token in params field of the request
JsonObject params = (JsonObject) request.get("params");
JsonObject authObject = (JsonObject) context.serialize(src.getAuthToken());
for (Entry entry : authObject.entrySet()) {
params.add(entry.getKey(), entry.getValue());
}
}
return request;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy