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

com.datastax.driver.dse.graph.GraphSONSerializerProvider Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 2.4.0
Show newest version
/*
 * 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.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

/**
 * Implementation of the {@link DefaultSerializerProvider} for Jackson that uses the {@link
 * ToStringSerializer} for unknown types.
 */
final class GraphSONSerializerProvider extends DefaultSerializerProvider {
  private static final long serialVersionUID = 1L;
  private final JsonSerializer unknownTypeSerializer;

  public GraphSONSerializerProvider() {
    super();
    // TODO
    //        setDefaultKeySerializer(new GraphSONSerializersV1d0.GraphSONKeySerializer());
    unknownTypeSerializer = new ToStringGraphSON2Serializer();
  }

  protected GraphSONSerializerProvider(
      final SerializerProvider src,
      final SerializationConfig config,
      final SerializerFactory f,
      final JsonSerializer unknownTypeSerializer) {
    super(src, config, f);
    this.unknownTypeSerializer = unknownTypeSerializer;
  }

  @Override
  public JsonSerializer getUnknownTypeSerializer(final Class aClass) {
    return unknownTypeSerializer;
  }

  @Override
  public GraphSONSerializerProvider createInstance(
      final SerializationConfig config, final SerializerFactory jsf) {
    // createInstance is called pretty often to create a new SerializerProvider
    // we give it the unknownTypeSerializer that we had in the first place,
    // when the object was first constructed through the public constructor
    // that has a GraphSONVersion.
    return new GraphSONSerializerProvider(this, config, jsf, unknownTypeSerializer);
  }
}