All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
spinjar.com.fasterxml.jackson.databind.ser.std.EnumSetSerializer Maven / Gradle / Ivy
package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
@SuppressWarnings("serial")
public class EnumSetSerializer
extends AsArraySerializerBase>>
{
/**
* @since 2.6
*/
public EnumSetSerializer(JavaType elemType) {
super(EnumSet.class, elemType, true, null, null);
}
public EnumSetSerializer(EnumSetSerializer src,
BeanProperty property, TypeSerializer vts, JsonSerializer valueSerializer,
Boolean unwrapSingle) {
super(src, property, vts, valueSerializer, unwrapSingle);
}
@Override
public EnumSetSerializer _withValueTypeSerializer(TypeSerializer vts) {
// no typing for enums (always "hard" type)
return this;
}
@Override
public EnumSetSerializer withResolved(BeanProperty property,
TypeSerializer vts, JsonSerializer elementSerializer,
Boolean unwrapSingle) {
return new EnumSetSerializer(this, property, vts, elementSerializer, unwrapSingle);
}
@Override
public boolean isEmpty(SerializerProvider prov, EnumSet> value) {
return value.isEmpty();
}
@Override
public boolean hasSingleElement(EnumSet> value) {
return value.size() == 1;
}
@Override
public final void serialize(EnumSet> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null)
&& provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(value, len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(EnumSet> value, JsonGenerator gen,
SerializerProvider provider)
throws IOException
{
JsonSerializer enumSer = _elementSerializer;
/* Need to dynamically find instance serializer; unfortunately
* that seems to be the only way to figure out type (no accessors
* to the enum class that set knows)
*/
for (Enum en : value) {
if (enumSer == null) {
// 12-Jan-2010, tatu: Since enums cannot be polymorphic, let's
// not bother with typed serializer variant here
enumSer = provider.findContentValueSerializer(en.getDeclaringClass(), _property);
}
enumSer.serialize(en, gen, provider);
}
}
}