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

org.kiwiproject.json.JaxbElementSerializer Maven / Gradle / Ivy

Go to download

Kiwi is a utility library. We really like Google's Guava, and also use Apache Commons. But if they don't have something we need, and we think it is useful, this is where we put it.

There is a newer version: 4.5.2
Show newest version
package org.kiwiproject.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import javax.xml.bind.JAXBElement;
import java.io.IOException;

/**
 * A Jackson {@link JsonSerializer} that serializes {@link JAXBElement} objects, with "nil" values handled by writing
 * a JSON null.
 * 

* Note that jackson-core and jackson-databind must be available at runtime. * * @see JAXBElement#isNil() */ public class JaxbElementSerializer extends JsonSerializer { @Override public void serialize(JAXBElement jaxbElement, JsonGenerator gen, SerializerProvider serializers) throws IOException { if (jaxbElement.isNil()) { gen.writeNull(); } else { gen.writeObject(jaxbElement.getValue()); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy