com.datastax.driver.dse.graph.GraphSON1DefaultModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dse-java-driver-core Show documentation
Show all versions of dse-java-driver-core Show documentation
A driver for DataStax Enterprise (DSE)
and Apache Cassandra 1.2+ clusters that works exclusively with the
Cassandra Query Language version 3 (CQL3) and Cassandra's binary protocol,
supporting DSE-specific features such as geospatial types, DSE Graph and DSE authentication.
/*
* Copyright DataStax, Inc.
*
* This software can be used solely with DataStax Enterprise. Please consult the license at
* http://www.datastax.com/terms/datastax-dse-driver-license-terms
*/
package com.datastax.driver.dse.graph;
import com.datastax.driver.dse.geometry.Geometry;
import com.datastax.driver.dse.geometry.LineString;
import com.datastax.driver.dse.geometry.Point;
import com.datastax.driver.dse.geometry.Polygon;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.List;
import java.util.Map;
/**
* The default Jackson module used by DSE Graph.
*/
class GraphSON1DefaultModule extends SimpleModule {
GraphSON1DefaultModule(String name, Version version) {
super(name, version, createDeserializers(), createSerializers());
}
private static Map, JsonDeserializer>> createDeserializers() {
DefaultEdgeDeserializer edgeDeserializer = new DefaultEdgeDeserializer();
DefaultVertexDeserializer vertexDeserializer = new DefaultVertexDeserializer();
DefaultPathDeserializer pathDeserializer = new DefaultPathDeserializer();
DefaultPropertyDeserializer propertyDeserializer = new DefaultPropertyDeserializer();
DefaultVertexPropertyDeserializer vertexPropertyDeserializer = new DefaultVertexPropertyDeserializer();
return ImmutableMap., JsonDeserializer>>builder()
.put(Edge.class, edgeDeserializer)
.put(Vertex.class, vertexDeserializer)
.put(Path.class, pathDeserializer)
.put(Property.class, propertyDeserializer)
.put(VertexProperty.class, vertexPropertyDeserializer)
// Inet (there is no built-in deserializer for InetAddress and subclasses)
.put(InetAddress.class, new DefaultInetAddressDeserializer(InetAddress.class))
.put(Inet4Address.class, new DefaultInetAddressDeserializer(Inet4Address.class))
.put(Inet6Address.class, new DefaultInetAddressDeserializer(Inet6Address.class))
// Geospatial types
.put(Geometry.class, new DefaultGeometryDeserializer(Geometry.class))
.put(Point.class, new DefaultGeometryDeserializer(Point.class))
.put(LineString.class, new DefaultGeometryDeserializer(LineString.class))
.put(Polygon.class, new DefaultGeometryDeserializer(Polygon.class))
.build();
}
private static List> createSerializers() {
return ImmutableList.>builder()
.add(new DefaultGraphNodeSerializer())
.add(new DefaultElementSerializer())
.add(new DefaultGeometrySerializer())
.build();
}
}