Search in sources :

Example 1 with DeserializationFeature

use of com.fasterxml.jackson.databind.DeserializationFeature in project swagger-core by swagger-api.

the class SimpleGenerationTest method testJsonValue_Ticket3409.

@Test
public void testJsonValue_Ticket3409() throws Exception {
    DeserializationFeature aa = DeserializationFeature.valueOf("FAIL_ON_UNKNOWN_PROPERTIES");
    Map<String, Schema> models = ModelConverters.getInstance().readAll(PlanetName.Planet.class);
    assertNotNull(models.get("Planet"));
    if (isJacksonAtLeast2_9()) {
        assertNull(models.get("PlanetName"));
        assertEquals(((Schema) models.get("Planet").getProperties().get("name")).getType(), "string");
    }
}
Also used : DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 2 with DeserializationFeature

use of com.fasterxml.jackson.databind.DeserializationFeature 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 3 with DeserializationFeature

use of com.fasterxml.jackson.databind.DeserializationFeature 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)

Aggregations

DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)3 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)2 Module (com.fasterxml.jackson.databind.Module)2 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)2 JaxbAnnotationModule (com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 Schema (io.swagger.v3.oas.models.media.Schema)1 Test (org.testng.annotations.Test)1