Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.JavaType


  @Override
  protected boolean canConvertFrom(Message<?> message, Class<?> targetClass) {
    if (targetClass == null) {
      return false;
    }
    JavaType javaType = this.objectMapper.constructType(targetClass);
    if (!jackson23Available || !logger.isWarnEnabled()) {
      return (this.objectMapper.canDeserialize(javaType) && supportsMimeType(message.getHeaders()));
    }
    AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
    if (this.objectMapper.canDeserialize(javaType, causeRef) && supportsMimeType(message.getHeaders())) {
View Full Code Here


    throw new UnsupportedOperationException();
  }

  @Override
  public Object convertFromInternal(Message<?> message, Class<?> targetClass) {
    JavaType javaType = this.objectMapper.constructType(targetClass);
    Object payload = message.getPayload();
    try {
      if (payload instanceof byte[]) {
        return this.objectMapper.readValue((byte[]) payload, javaType);
      }
View Full Code Here

                /* As per [Issue#305], need to provide contextual info. But for
                 * backwards compatibility, let's start by only supporting this
                 * for base class, not via interface. Later on we can add this
                 * to the interface, assuming deprecation at base class helps.
                 */
                JavaType type;
                if (_idResolver instanceof TypeIdResolverBase) {
                    type = ((TypeIdResolverBase) _idResolver).typeFromId(ctxt, typeId);
                } else {
                    type = _idResolver.typeFromId(typeId);
                }
                if (type == null) {
                    // As per [JACKSON-614], use the default impl if no type id available:
                    if (_defaultImpl == null) {
                        throw ctxt.unknownTypeException(_baseType, typeId);
                    }
                    deser = _findDefaultImplDeserializer(ctxt);
                } else {
                    /* 16-Dec-2010, tatu: Since nominal type we get here has no (generic) type parameters,
                     *   we actually now need to explicitly narrow from base type (which may have parameterization)
                     *   using raw type.
                     *  
                     *   One complication, though; can not change 'type class' (simple type to container); otherwise
                     *   we may try to narrow a SimpleType (Object.class) into MapType (Map.class), losing actual
                     *   type in process (getting SimpleType of Map.class which will not work as expected)
                     */
                    if (_baseType != null && _baseType.getClass() == type.getClass()) {
                        type = _baseType.narrowBy(type.getRawClass());
                    }
                    deser = ctxt.findContextualValueDeserializer(type, _property);
                }
                _deserializers.put(typeId, deser);
            }
View Full Code Here

    @Override
    public JavaType modifyType(JavaType type, Type jdkType, TypeBindings context, TypeFactory typeFactory)
    {
        final Class<?> raw = type.getRawClass();
        if (Multimap.class.isAssignableFrom(raw)) {
            JavaType keyType = type.containedType(0);
            JavaType contentType = type.containedType(1);

            if (keyType == null) {
                keyType = TypeFactory.unknownType();
            }
            if (contentType == null) {
                contentType = TypeFactory.unknownType();
            }
            return typeFactory.constructMapLikeType(type.getRawClass(), keyType, contentType);
        }
        /* Guava 12 changed the implementation of their {@link FluentIterable} to include a method named "isEmpty."  This method
         * causes Jackson to treat FluentIterables as a Bean instead of an {@link Iterable}.  Serialization of FluentIterables by
         * default result in a string like "{\"empty\":true}."  This module modifies the JavaType of FluentIterable to be
         * the same as Iterable.
         */
        /* Hmmh. This won't work too well for deserialization. But I guess it'll
         * have to do for now...
         */
        if (FluentIterable.class.isAssignableFrom(raw)) {
            JavaType[] types = typeFactory.findTypeParameters(type, Iterable.class);
            JavaType elemType = (types == null || types.length < 1)
                    ? null : types[0];
            if (elemType == null) {
                elemType = TypeFactory.unknownType();
            }
            return typeFactory.constructParametricType(Iterable.class,  elemType);
View Full Code Here

        serialize(value, jgen, provider);
    }

    @Override
    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
        JavaType typeParameter = typeHint.containedType(0);
        if (typeParameter != null) {
            visitor.getProvider().findValueSerializer(typeParameter, null).acceptJsonFormatVisitor(visitor, typeParameter);
            return;
        }
        super.acceptJsonFormatVisitor(visitor, typeHint);
View Full Code Here

                        ListResponse.MinimalItemListResponse.class));
        /* "full" ListItemType is trickier, since we need to use generic type definition
         * to parameterize appropriate Full
         */
        // Ugh. Jackson's type resolution fails if using "FullItemListResponse"... need to work around it
        JavaType fullResponseType = config.getJsonMapper().getTypeFactory().constructParametricType(
                ListResponse.class, listItemType);
        _listReaders.put(ListItemType.fullEntries,
                new GenericContentConverter<ListResponse<ListItem>>(mapper, fullResponseType));
    }
View Full Code Here

     * certainly require access to this instance (at least "List" and "Map" ones)
     */
    @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

                        ListResponse.MinimalItemListResponse.class));
        /* "full" ListItemType is trickier, since we need to use generic type definition
         * to parameterize appropriate Full
         */
        // Ugh. Jackson's type resolution fails if using "FullItemListResponse"... need to work around it
        JavaType fullResponseType = config.getJsonMapper().getTypeFactory().constructParametricType(
                ListResponse.class, listItemType);
        _listReaders.put(ListItemType.fullEntries,
                new GenericContentConverter<ListResponse<ListItem>>(mapper, fullResponseType));
    }
View Full Code Here

        @Override
        public boolean canCreateFromObjectWith() { return true; }
       
        @Override
        public CreatorProperty[] getFromObjectArguments(DeserializationConfig config) {
            JavaType intType = config.constructType(Integer.TYPE);
            JavaType longType = config.constructType(Long.TYPE);
            return  new CreatorProperty[] {
                    creatorProp("sourceRef", config.constructType(Object.class), 0),
                    creatorProp("byteOffset", longType, 1),
                    creatorProp("charOffset", longType, 2),
                    creatorProp("lineNr", intType, 3),
View Full Code Here

                if (forDeser) {
                    /* 24-Feb-2011, tatu: [JACKSON-498] One more problem; sometimes
                     *   we have same name for multiple types; if so, use most specific
                     *   one.
                     */
                    JavaType prev = idToType.get(id);
                    if (prev != null) { // Can only override if more specific
                        if (cls.isAssignableFrom(prev.getRawClass())) { // nope, more generic (or same)
                            continue;
                        }
                    }
                    idToType.put(id, config.constructType(cls));
                }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.JavaType

Copyright © 2018 www.massapicom. 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.