org.kiwiproject.json.JaxbElementSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kiwi Show documentation
Show all versions of kiwi Show documentation
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.
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