Examples of TypeFactory


Examples of com.fasterxml.jackson.databind.type.TypeFactory

                mapper._deserializationContext = mapper._deserializationContext.with(df);
            }

//          @Override
            public void addTypeModifier(TypeModifier modifier) {
                TypeFactory f = mapper._typeFactory;
                f = f.withModifier(modifier);
                mapper.setTypeFactory(f);
            }

//          @Override
            public void addValueInstantiators(ValueInstantiators instantiators) {
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

          return conversionService.convert(value, TypeDescriptor.forObject(value),
              methodParameter.getTypeDescriptor());
        } catch (ConversionFailedException e) {
          // ignore this exception for collections and arrays.
          // try to convert the value with jackson
          TypeFactory typeFactory = jsonHandler.getMapper().getTypeFactory();
          if (methodParameter.getTypeDescriptor().isCollection()) {
            JavaType type = CollectionType.construct(
                methodParameter.getType(),
                typeFactory.constructType(methodParameter.getTypeDescriptor()
                    .getElementTypeDescriptor().getType()));
            return jsonHandler.convertValue(value, type);
          } else if (methodParameter.getTypeDescriptor().isArray()) {
            JavaType type = typeFactory.constructArrayType(methodParameter.getTypeDescriptor()
                .getElementTypeDescriptor().getType());
            return jsonHandler.convertValue(value, type);
          }

          throw e;
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

    @Override
    public void resolve(DeserializationContext ctxt) throws JsonMappingException
    {
        JavaType obType = ctxt.constructType(Object.class);
        JavaType stringType = ctxt.constructType(String.class);
        TypeFactory tf = ctxt.getTypeFactory();
        _mapDeserializer = _findCustomDeser(ctxt, tf.constructMapType(Map.class, stringType, obType));
        _listDeserializer = _findCustomDeser(ctxt, tf.constructCollectionType(List.class, obType));
        _stringDeserializer = _findCustomDeser(ctxt, stringType);
        _numberDeserializer = _findCustomDeser(ctxt, tf.constructType(Number.class));
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
        throws JsonMappingException
    {
        JsonArrayFormatVisitor arrayVisitor = visitor.expectArrayFormat(typeHint);
        if (arrayVisitor != null) {
            TypeFactory tf = visitor.getProvider().getTypeFactory();
            JavaType contentType = tf.moreSpecificType(_elementType, typeHint.getContentType());
            if (contentType == null) {
                throw new JsonMappingException("Could not resolve type");
            }
            JsonSerializer<?> valueSer = _elementSerializer;
            if (valueSer == null) {
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

    }

    public void testJavaType() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        TypeFactory tf = TypeFactory.defaultInstance();
        // first simple type:
        String json = mapper.writeValueAsString(tf.constructType(String.class));
        assertEquals(quote(java.lang.String.class.getName()), json);
        // and back
        JavaType t = mapper.readValue(json, JavaType.class);
        assertNotNull(t);
        assertEquals(String.class, t.getRawClass());
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

    @SuppressWarnings("serial")
    static class HashTree<K, V> extends HashMap<K, HashTree<K, V>> { }

    public void testRecursiveType()
    {
        TypeFactory tf = TypeFactory.defaultInstance();
        JavaType type = tf.constructType(HashTree.class);
        assertNotNull(type);
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

   
    // First things first: must be able to load the deserializers...
    public void testDeserializerLoading()
    {
        CoreXMLDeserializers sers = new CoreXMLDeserializers();
        TypeFactory f = TypeFactory.defaultInstance();
        sers.findBeanDeserializer(f.constructType(Duration.class), null, null);
        sers.findBeanDeserializer(f.constructType(XMLGregorianCalendar.class), null, null);
        sers.findBeanDeserializer(f.constructType(QName.class), null, null);
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

    /**********************************************************
     */
   
    public void testMaps()
    {
        TypeFactory tf = TypeFactory.defaultInstance();
        JavaType t = tf.constructType(new TypeReference<LongValuedMap<String>>() { });
        MapType type = (MapType) t;
        assertSame(LongValuedMap.class, type.getRawClass());
        assertEquals(tf.constructType(String.class), type.getKeyType());
        assertEquals(tf.constructType(Long.class), type.getContentType());       
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

    public void testList()
    {
        JavaType t;

        TypeFactory tf = TypeFactory.defaultInstance();
        t = tf.constructType(new TypeReference<MyLongList<Integer>>() {});
        CollectionType type = (CollectionType) t;
        assertSame(MyLongList.class, type.getRawClass());
        assertEquals(tf.constructType(Long.class), type.getContentType());       

        t = tf.constructType(LongList.class);
        type = (CollectionType) t;
        assertSame(LongList.class, type.getRawClass());
        assertEquals(tf.constructType(Long.class), type.getContentType());       
    }
View Full Code Here

Examples of com.fasterxml.jackson.databind.type.TypeFactory

        return targetType.isAssignableFrom(findAdapterBoundType(adapter));
    }

    private Class<?> findAdapterBoundType(XmlAdapter<?,?> adapter)
    {
        TypeFactory tf = getTypeFactory();
        JavaType adapterType = tf.constructType(adapter.getClass());
        JavaType[] params = tf.findTypeParameters(adapterType, XmlAdapter.class);
        // should not happen, except if our type resolution has a flaw, but:
        if (params == null || params.length < 2) {
            return Object.class;
        }
        return params[1].getRawClass();
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.