Examples of JaxbAnnotationIntrospector


Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

    }

    private ObjectMapper getObjectMapper() throws IOException {
        if (this.objectMapper == null) {
            ObjectMapper objectMapper = new ObjectMapper();
            AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
            SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
            serializationConfig = serializationConfig.without(SerializationConfig.Feature.WRAP_ROOT_VALUE)
                    .with(SerializationConfig.Feature.INDENT_OUTPUT)
                    .withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL)
                    .withSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY)
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

*
*/
public class JacksonHelper {
    public static ObjectMapper createObjectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
        AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
        AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary);
        mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
        // [rfeng] To avoid complaints about javaClass
        mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

     */
    public void testWithJAXB() throws Exception
    {
        String jsonData = "{\"id\":1}";
        ObjectMapper mapper = new ObjectMapper();
        mapper.getDeserializationConfig().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
        mapper.readValue(jsonData, JaxbBean.class);

    }
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

     */

    public void testAutoDetectDisable() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        mapper.getSerializationConfig().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
        Jackson183Bean bean = new Jackson183Bean();
        Map<String,Object> result;

        // Ok: by default, should see 2 fields:
        result = writeAndMap(mapper, bean);
        assertEquals(2, result.size());
        assertEquals("a", result.get("a"));
        assertEquals("b", result.get("b"));

        // But when disabling auto-detection, just one
        mapper = new ObjectMapper();
        mapper.getSerializationConfig().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
        mapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, false);
        result = writeAndMap(mapper, bean);
        assertEquals(1, result.size());
        assertNull(result.get("a"));
        assertEquals("b", result.get("b"));
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

     */

    public void testDetection() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        mapper.getSerializationConfig().setAnnotationIntrospector(new JaxbAnnotationIntrospector());

        Map<String,Object> result = writeAndMap(mapper, new SimpleBean());
        assertEquals(3, result.size());
        assertEquals("1", result.get("jaxb"));
        assertEquals("2", result.get("jaxb2"));
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

     * tests getting serializer/deserializer instances.
     */
    public void testSerializeDeserializeWithJaxbAnnotations() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        mapper.getSerializationConfig().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
        mapper.getDeserializationConfig().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
        mapper.getSerializationConfig().set(SerializationConfig.Feature.INDENT_OUTPUT, true);
        JaxbExample ex = new JaxbExample();
        QName qname = new QName("urn:hi", "hello");
        ex.setQname(qname);
        ex.setAttributeProperty("attributeValue");
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

        assertNull(readEx.propertyToIgnore);
    }

    public void testNamespaceAccess() throws Exception
    {
        AnnotationIntrospector ai = new JaxbAnnotationIntrospector();
        assertEquals("urn:class", ai.findNamespace(AnnotatedClass.construct(NamespaceBean.class, ai, null)));
        /* should it return null or empty String? Should be null
         * for no annotations; empty for explicitly empty NS.
         */
        assertNull(ai.findNamespace(AnnotatedClass.construct(SimpleBean.class, ai, null)));
    }
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

        assertNull(ai.findNamespace(AnnotatedClass.construct(SimpleBean.class, ai, null)));
    }

    public void testRootNameAccess() throws Exception
    {
        AnnotationIntrospector ai = new JaxbAnnotationIntrospector();
        // If no @XmlRootElement, should get null (unless pkg has etc)
        assertNull(ai.findRootName(AnnotatedClass.construct(SimpleBean.class, ai, null)));
        // With @XmlRootElement, but no name, empty String
        assertEquals("", ai.findRootName(AnnotatedClass.construct(NamespaceBean.class, ai, null)));
        // and otherwise explicit name
        assertEquals("test", ai.findRootName(AnnotatedClass.construct(RootNameBean.class, ai, null)));
    }
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

     * cyclic is not a problem (instances are).
     */
    public void testWithJAXB() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        mapper.getDeserializationConfig().setAnnotationIntrospector(new JaxbAnnotationIntrospector());
        Map<String,Object> results = writeAndMap(mapper, new Bean(null, "abx"));
        assertEquals(2, results.size());
        assertEquals("abx", results.get("name"));
        assertTrue(results.containsKey("next"));
        assertNull(results.get("next"));
View Full Code Here

Examples of org.codehaus.jackson.xc.JaxbAnnotationIntrospector

    }


    private static Pair createJaxbJacksonAnnotationIntrospector() {

        AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector();
        AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();

        return new AnnotationIntrospector.Pair(jacksonIntrospector, jaxbIntrospector);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.