Search in sources :

Example 6 with JaxbAnnotationModule

use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project CFLint by cflint.

the class ConfigUtils method unmarshalJson.

public static <E> E unmarshalJson(final Reader reader, final Class<E> expectedClass) throws IOException {
    final ObjectMapper objectMapper = new ObjectMapper();
    final JaxbAnnotationModule module = new JaxbAnnotationModule();
    objectMapper.registerModule(module);
    return objectMapper.readValue(reader, expectedClass);
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with JaxbAnnotationModule

use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project camel by apache.

the class JacksonXMLDataFormat method doStart.

@Override
protected void doStart() throws Exception {
    if (xmlMapper == null) {
        xmlMapper = new XmlMapper();
    }
    if (enableJaxbAnnotationModule) {
        // Enables JAXB processing
        JaxbAnnotationModule module = new JaxbAnnotationModule();
        LOG.info("Registering module: {}", module);
        xmlMapper.registerModule(module);
    }
    if (useList) {
        setCollectionType(ArrayList.class);
    }
    if (include != null) {
        JsonInclude.Include inc = getCamelContext().getTypeConverter().mandatoryConvertTo(JsonInclude.Include.class, include);
        xmlMapper.setSerializationInclusion(inc);
    }
    if (prettyPrint) {
        xmlMapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    if (enableFeatures != null) {
        Iterator<Object> it = ObjectHelper.createIterator(enableFeatures);
        while (it.hasNext()) {
            String enable = it.next().toString();
            // it can be different kind
            SerializationFeature sf = getCamelContext().getTypeConverter().tryConvertTo(SerializationFeature.class, enable);
            if (sf != null) {
                xmlMapper.enable(sf);
                continue;
            }
            DeserializationFeature df = getCamelContext().getTypeConverter().tryConvertTo(DeserializationFeature.class, enable);
            if (df != null) {
                xmlMapper.enable(df);
                continue;
            }
            MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, enable);
            if (mf != null) {
                xmlMapper.enable(mf);
                continue;
            }
            throw new IllegalArgumentException("Enable feature: " + enable + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]");
        }
    }
    if (disableFeatures != null) {
        Iterator<Object> it = ObjectHelper.createIterator(disableFeatures);
        while (it.hasNext()) {
            String disable = it.next().toString();
            // it can be different kind
            SerializationFeature sf = getCamelContext().getTypeConverter().tryConvertTo(SerializationFeature.class, disable);
            if (sf != null) {
                xmlMapper.disable(sf);
                continue;
            }
            DeserializationFeature df = getCamelContext().getTypeConverter().tryConvertTo(DeserializationFeature.class, disable);
            if (df != null) {
                xmlMapper.disable(df);
                continue;
            }
            MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, disable);
            if (mf != null) {
                xmlMapper.disable(mf);
                continue;
            }
            throw new IllegalArgumentException("Disable feature: " + disable + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]");
        }
    }
    if (modules != null) {
        for (Module module : modules) {
            LOG.info("Registering module: {}", module);
            xmlMapper.registerModules(module);
        }
    }
    if (moduleClassNames != null) {
        Iterable<Object> it = ObjectHelper.createIterable(moduleClassNames);
        for (Object o : it) {
            String name = o.toString();
            Class<Module> clazz = camelContext.getClassResolver().resolveMandatoryClass(name, Module.class);
            Module module = camelContext.getInjector().newInstance(clazz);
            LOG.info("Registering module: {} -> {}", name, module);
            xmlMapper.registerModule(module);
        }
    }
    if (moduleRefs != null) {
        Iterable<Object> it = ObjectHelper.createIterable(moduleRefs);
        for (Object o : it) {
            String name = o.toString();
            if (name.startsWith("#")) {
                name = name.substring(1);
            }
            Module module = CamelContextHelper.mandatoryLookup(camelContext, name, Module.class);
            LOG.info("Registering module: {} -> {}", name, module);
            xmlMapper.registerModule(module);
        }
    }
}
Also used : DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) Module(com.fasterxml.jackson.databind.Module) JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule)

Example 8 with JaxbAnnotationModule

use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project camel by apache.

the class JacksonDataFormat method doStart.

@Override
protected void doStart() throws Exception {
    if (objectMapper == null) {
        objectMapper = new ObjectMapper();
    }
    if (enableJaxbAnnotationModule) {
        // Enables JAXB processing
        JaxbAnnotationModule module = new JaxbAnnotationModule();
        LOG.debug("Registering JaxbAnnotationModule: {}", module);
        objectMapper.registerModule(module);
    }
    if (useList) {
        setCollectionType(ArrayList.class);
    }
    if (include != null) {
        JsonInclude.Include inc = getCamelContext().getTypeConverter().mandatoryConvertTo(JsonInclude.Include.class, include);
        objectMapper.setSerializationInclusion(inc);
    }
    if (prettyPrint) {
        objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    if (enableFeatures != null) {
        Iterator<Object> it = ObjectHelper.createIterator(enableFeatures);
        while (it.hasNext()) {
            String enable = it.next().toString();
            // it can be different kind
            SerializationFeature sf = getCamelContext().getTypeConverter().tryConvertTo(SerializationFeature.class, enable);
            if (sf != null) {
                objectMapper.enable(sf);
                continue;
            }
            DeserializationFeature df = getCamelContext().getTypeConverter().tryConvertTo(DeserializationFeature.class, enable);
            if (df != null) {
                objectMapper.enable(df);
                continue;
            }
            MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, enable);
            if (mf != null) {
                objectMapper.enable(mf);
                continue;
            }
            throw new IllegalArgumentException("Enable feature: " + enable + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]");
        }
    }
    if (disableFeatures != null) {
        Iterator<Object> it = ObjectHelper.createIterator(disableFeatures);
        while (it.hasNext()) {
            String disable = it.next().toString();
            // it can be different kind
            SerializationFeature sf = getCamelContext().getTypeConverter().tryConvertTo(SerializationFeature.class, disable);
            if (sf != null) {
                objectMapper.disable(sf);
                continue;
            }
            DeserializationFeature df = getCamelContext().getTypeConverter().tryConvertTo(DeserializationFeature.class, disable);
            if (df != null) {
                objectMapper.disable(df);
                continue;
            }
            MapperFeature mf = getCamelContext().getTypeConverter().tryConvertTo(MapperFeature.class, disable);
            if (mf != null) {
                objectMapper.disable(mf);
                continue;
            }
            throw new IllegalArgumentException("Disable feature: " + disable + " cannot be converted to an accepted enum of types [SerializationFeature,DeserializationFeature,MapperFeature]");
        }
    }
    if (modules != null) {
        for (Module module : modules) {
            LOG.debug("Registering module: {}", module);
            objectMapper.registerModules(module);
        }
    }
    if (moduleClassNames != null) {
        Iterable<Object> it = ObjectHelper.createIterable(moduleClassNames);
        for (Object o : it) {
            String name = o.toString();
            Class<Module> clazz = camelContext.getClassResolver().resolveMandatoryClass(name, Module.class);
            Module module = camelContext.getInjector().newInstance(clazz);
            LOG.debug("Registering module: {} -> {}", name, module);
            objectMapper.registerModule(module);
        }
    }
    if (moduleRefs != null) {
        Iterable<Object> it = ObjectHelper.createIterable(moduleRefs);
        for (Object o : it) {
            String name = o.toString();
            if (name.startsWith("#")) {
                name = name.substring(1);
            }
            Module module = CamelContextHelper.mandatoryLookup(camelContext, name, Module.class);
            LOG.debug("Registering module: {} -> {}", name, module);
            objectMapper.registerModule(module);
        }
    }
}
Also used : DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) Module(com.fasterxml.jackson.databind.Module) JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with JaxbAnnotationModule

use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project ORCID-Source by ORCID.

the class MemberSwaggerResource method scan.

/**
 * Scan the classes and add in the OAuth information
 */
@Override
protected synchronized Swagger scan(Application app) {
    // tell swagger to pick up our jaxb annotations
    Json.mapper().registerModule(new JaxbAnnotationModule());
    Swagger s = super.scan(app);
    OAuth2Definition oauth = new OAuth2Definition();
    oauth.accessCode(this.authEndPoint, this.tokenEndPoint);
    oauth.scope(ScopePathType.READ_LIMITED.value(), "Read Limited record");
    oauth.scope(ScopePathType.PERSON_UPDATE.value(), "Update person");
    oauth.scope(ScopePathType.ACTIVITIES_UPDATE.value(), "Update activities");
    s.securityDefinition("orcid_auth", oauth);
    OAuth2Definition oauthTwoLegs = new OAuth2Definition();
    oauthTwoLegs.application(this.tokenEndPoint);
    oauthTwoLegs.scope(ScopePathType.PREMIUM_NOTIFICATION.value(), "Notifications");
    oauthTwoLegs.scope(ScopePathType.READ_PUBLIC.value(), "Read Public record");
    oauthTwoLegs.scope(ScopePathType.GROUP_ID_RECORD_READ.value(), "Read groups");
    oauthTwoLegs.scope(ScopePathType.GROUP_ID_RECORD_UPDATE.value(), "Update groups");
    s.securityDefinition("orcid_two_legs", oauthTwoLegs);
    return s;
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) Swagger(io.swagger.models.Swagger) OAuth2Definition(io.swagger.models.auth.OAuth2Definition)

Example 10 with JaxbAnnotationModule

use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project minijax by minijax.

the class Json method getObjectMapper.

public static ObjectMapper getObjectMapper() {
    if (instance == null) {
        instance = new ObjectMapper();
        instance.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        instance.setSerializationInclusion(Include.NON_NULL);
        instance.registerModule(new JaxbAnnotationModule());
        instance.registerModule(new JavaTimeModule());
        instance.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        instance.registerModule(new AfterburnerModule());
    }
    return instance;
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JaxbAnnotationModule (com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 StringWriter (java.io.StringWriter)3 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)2 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)2 Module (com.fasterxml.jackson.databind.Module)2 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)2 Swagger (io.swagger.models.Swagger)2 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)1 IOException (java.io.IOException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 HelloRequestType (org.openecard.ws.chipgateway.HelloRequestType)1 Test (org.testng.annotations.Test)1