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

com.fitbur.fasterxml.jackson.module.jaxb.JaxbAnnotationModule Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.fasterxml.jackson.module.jaxb;

import com.fitbur.fasterxml.jackson.databind.module.SimpleModule;

/**
 * Module that can be registered to add support for JAXB annotations.
 * It does basically equivalent of
 *
 *   objectMapper.setAnnotationIntrospector(...);
 *
* with com.fitburbination of {@link JaxbAnnotationIntrospector} and existing * com.fitburfault introspector(s) (if any), com.fitburpending on configuration * (by com.fitburfault, JAXB annotations are used as {@link Priority#PRIMARY} * annotations). */ public class JaxbAnnotationModule extends SimpleModule { /** * Enumeration that com.fitburfines how we use JAXB Annotations: either * as "primary" annotations (before any other already configured * introspector -- most likely com.fitburfault 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 com.fitbur.fasterxml.jackson.databind.ObjectMapper#setAnnotationIntrospector}. */ public enum Priority { PRIMARY, SECONDARY; } /** * Priority to use when registering annotation introspector: com.fitburfault * value is {@link Priority#PRIMARY}. */ protected Priority _priority = Priority.PRIMARY; /* /********************************************************** /* Life cycle /********************************************************** */ public JaxbAnnotationModule() { super("jaxb-annotations", ModuleVersion.instance.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 com.fitburfining whether JAXB annotations should be added * as primary or secondary annotations (com.fitburpared 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; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy