io.sentry.adapters.OrientationSerializerAdapter Maven / Gradle / Ivy
package io.sentry.adapters;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import io.sentry.ILogger;
import io.sentry.SentryLevel;
import io.sentry.protocol.Device;
import java.lang.reflect.Type;
import java.util.Locale;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ApiStatus.Internal
public final class OrientationSerializerAdapter
implements JsonSerializer {
private final @NotNull ILogger logger;
public OrientationSerializerAdapter(final @NotNull ILogger logger) {
this.logger = logger;
}
@Override
public JsonElement serialize(
Device.DeviceOrientation src, Type typeOfSrc, JsonSerializationContext context) {
try {
return src == null ? null : new JsonPrimitive(src.name().toLowerCase(Locale.ROOT));
} catch (Exception e) {
logger.log(SentryLevel.ERROR, "Error when serializing DeviceOrientation", e);
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy