io.druid.jackson.DruidDefaultSerializersModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of druid-processing Show documentation
Show all versions of druid-processing Show documentation
A module that is everything required to understands Druid Segments
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package io.druid.jackson;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.google.common.base.Throwables;
import com.metamx.common.Granularity;
import com.metamx.common.guava.Accumulator;
import com.metamx.common.guava.Sequence;
import com.metamx.common.guava.Yielder;
import org.joda.time.DateTimeZone;
import java.io.IOException;
import java.nio.ByteOrder;
import java.util.TimeZone;
/**
*/
public class DruidDefaultSerializersModule extends SimpleModule
{
public DruidDefaultSerializersModule()
{
super("Druid default serializers");
JodaStuff.register(this);
addDeserializer(
Granularity.class,
new JsonDeserializer()
{
@Override
public Granularity deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
return Granularity.valueOf(jp.getText().toUpperCase());
}
}
);
addDeserializer(
DateTimeZone.class,
new JsonDeserializer()
{
@Override
public DateTimeZone deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
String tzId = jp.getText();
try {
return DateTimeZone.forID(tzId);
} catch(IllegalArgumentException e) {
// also support Java timezone strings
return DateTimeZone.forTimeZone(TimeZone.getTimeZone(tzId));
}
}
}
);
addSerializer(
DateTimeZone.class,
new JsonSerializer()
{
@Override
public void serialize(
DateTimeZone dateTimeZone,
JsonGenerator jsonGenerator,
SerializerProvider serializerProvider
)
throws IOException, JsonProcessingException
{
jsonGenerator.writeString(dateTimeZone.getID());
}
}
);
addSerializer(
Sequence.class,
new JsonSerializer()
{
@Override
public void serialize(Sequence value, final JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jgen.writeStartArray();
value.accumulate(
null,
new Accumulator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy