
org.testifyproject.fasterxml.jackson.module.jaxb.JaxbAnnotationModule Maven / Gradle / Ivy
package org.testifyproject.testifyproject.fasterxml.jackson.module.jaxb;
import org.testifyproject.testifyproject.fasterxml.jackson.core.Version;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.Module;
/**
* Module that can be registered to add support for JAXB annotations.
* It does basically equivalent of
*
* objectMapper.setAnnotationIntrospector(...);
*
* with org.testifyproject.testifyprojectbination of {@link JaxbAnnotationIntrospector} and existing
* org.testifyproject.testifyprojectfault introspector(s) (if any), org.testifyproject.testifyprojectpending on configuration
* (by org.testifyproject.testifyprojectfault, JAXB annotations are used as {@link Priority#PRIMARY}
* annotations).
*/
public class JaxbAnnotationModule extends Module
{
/**
* Enumeration that org.testifyproject.testifyprojectfines how we use JAXB Annotations: either
* as "primary" annotations (before any other already configured
* introspector -- most likely org.testifyproject.testifyprojectfault JacksonAnnotationIntrospector) or
* as "secondary" annotations (after any other already configured
* introspector(s)).
*
* Default choice is PRIMARY
*
* Note that if you want to use JAXB annotations as the only annotations,
* you must directly set annotation introspector by calling
* {@link org.testifyproject.testifyproject.fasterxml.jackson.databind.ObjectMapper#setAnnotationIntrospector}.
*/
public enum Priority {
PRIMARY, SECONDARY;
}
/**
* Priority to use when registering annotation introspector: org.testifyproject.testifyprojectfault
* value is {@link Priority#PRIMARY}.
*/
protected Priority _priority = Priority.PRIMARY;
/*
/**********************************************************
/* Life cycle
/**********************************************************
*/
public JaxbAnnotationModule() { }
@Override
public String getModuleName() {
return getClass().getSimpleName();
}
@Override
public Version version() {
return PackageVersion.VERSION;
}
@Override
public void setupModule(SetupContext context)
{
JaxbAnnotationIntrospector intr = new JaxbAnnotationIntrospector(context.getTypeFactory());
switch (_priority) {
case PRIMARY:
context.insertAnnotationIntrospector(intr);
break;
case SECONDARY:
context.appendAnnotationIntrospector(intr);
break;
}
}
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
/**
* Method for org.testifyproject.testifyprojectfining whether JAXB annotations should be added
* as primary or secondary annotations (org.testifyproject.testifyprojectpared to already registered
* annotations).
*
* NOTE: method MUST be called before registering the module -- calling
* afterwards will not have any effect on previous registrations.
*/
public JaxbAnnotationModule setPriority(Priority p) {
_priority = p;
return this;
}
public Priority getPriority() { return _priority; }
}