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

com.fitbur.fasterxml.jackson.databind.ser.std.BooleanSerializer Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.fasterxml.jackson.databind.ser.std;

import java.io.IOException;
import java.lang.reflect.Type;

import com.fitbur.fasterxml.jackson.core.JsonGenerationException;
import com.fitbur.fasterxml.jackson.core.JsonGenerator;
import com.fitbur.fasterxml.jackson.databind.JavaType;
import com.fitbur.fasterxml.jackson.databind.JsonNode;
import com.fitbur.fasterxml.jackson.databind.SerializerProvider;
import com.fitbur.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fitbur.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;

/**
 * Serializer used for primitive boolean, as well as java.util.Boolean
 * wrapper type.
 *

* Since this is one of "native" types, no type information is ever * included on serialization (unlike for most scalar types as of 1.5) */ @JacksonStdImpl public final class BooleanSerializer extends NonTypedScalarSerializerBase { /** * Whether type serialized is primitive (boolean) or wrapper * (java.lang.Boolean); if true, former, if false, latter. */ final boolean _forPrimitive; public BooleanSerializer(boolean forPrimitive) { super(Boolean.class); _forPrimitive = forPrimitive; } @Override public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeBoolean(value.booleanValue()); } @Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) { return createSchemaNode("boolean", !_forPrimitive); } @Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { visitor.expectBooleanFormat(typeHint); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy