Java Code Examples for com.fasterxml.jackson.databind.type.TypeFactory#unknownType()

The following examples show how to use com.fasterxml.jackson.databind.type.TypeFactory#unknownType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefRefMapSerializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
public RefRefMapSerializer(
        JavaType type, Class<? super T> mapClass,
        JsonSerializer<Object> keySerializer, TypeSerializer vts, JsonSerializer<Object> valueSerializer,
        Set<String> ignoredEntries
) {
    super(type, null);
    _type = type;
    // Assumes that the map class has first two type parameters corresponding to the key and the
    // value type.
    JavaType[] typeParameters = type.findTypeParameters(mapClass);
    JavaType keyType = (typeParameters.length > 0) ? typeParameters[0] : TypeFactory.unknownType();
    JavaType valueType = (typeParameters.length > 1) ? typeParameters[1] : TypeFactory.unknownType();
    _keyType = keyType;
    _valueType = valueType;
    _keySerializer = keySerializer;
    _valueTypeSerializer = vts;
    _valueSerializer = valueSerializer;
    _ignoredEntries = ignoredEntries;
}
 
Example 2
Source File: RangeDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    final RangeHelper.RangeProperties fieldNames = RangeHelper.getPropertyNames(ctxt.getConfig(),
            ctxt.getConfig().getPropertyNamingStrategy());
    JsonDeserializer<?> deser = _endpointDeserializer;
    if (deser == null) {
        JavaType endpointType = _rangeType.containedType(0);
        if (endpointType == null) { // should this ever occur?
            endpointType = TypeFactory.unknownType();
        }
        deser = ctxt.findContextualValueDeserializer(endpointType, property);
    } else {
        // 04-Sep-2019, tatu: If we already have a deserialize, should contextualize, right?
        deser = deser.createContextual(ctxt, property);
    }
    if ((deser != _endpointDeserializer) || (fieldNames != _fieldNames)) {
        return new RangeDeserializer(_rangeType, deser, _defaultBoundType, fieldNames);
    }
    return this;
}
 
Example 3
Source File: TestProduceJsonProcessor.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testdecodeResponseNull() throws Exception {
  JavaType resultType = TypeFactory.unknownType();
  Object result = pp.decodeResponse(Buffer.buffer(), resultType);
  Assert.assertNull(result);

  ByteArrayInputStream is = new ByteArrayInputStream(new byte[] {});
  try {
    pp.decodeResponse(is, resultType);
    Assert.fail();
  } catch (Exception e) {
    Assert.assertTrue(e instanceof MismatchedInputException);
  }
}
 
Example 4
Source File: TestProduceTextPlainProcessor.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testdecodeResponseNull() throws Exception {
  JavaType resultType = TypeFactory.unknownType();
  Object result = pp.decodeResponse(Buffer.buffer(), resultType);
  Assert.assertNull(result);

  ByteArrayInputStream is = new ByteArrayInputStream(new byte[] {});
  result = pp.decodeResponse(is, resultType);
  Assert.assertEquals(result, "");
}
 
Example 5
Source File: ContainerDeserializerBase.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Accessor for declared type of contained value elements; either exact
 * type, or one of its supertypes.
 */
public JavaType getContentType() {
    if (_containerType == null) {
        return TypeFactory.unknownType(); // should never occur but...
    }
    return _containerType.getContentType();
}
 
Example 6
Source File: SimpleBeanPropertyDefinition.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JavaType getPrimaryType() {
    if (_member == null) {
        return TypeFactory.unknownType();
    }
    return _member.getType();
}
 
Example 7
Source File: EclipseMapDeserializers.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
MapDeserializer<T, I, K, V> createDeserializer(JavaType type) {
    List<JavaType> typeParameters = null;
    TypeBindings bindings = type.getBindings();
    if (bindings != null) {
        typeParameters = bindings.getTypeParameters();
    }
    JavaType keyType;
    JavaType valueType;
    if (typeParameters != null && !typeParameters.isEmpty()) {
        if (refKey && refValue) {
            if (typeParameters.size() != 2) {
                throw new IllegalStateException(
                        "type parameters: " + typeParameters + ", expected exactly two");
            }
        } else if (refKey || refValue) {
            if (typeParameters.size() != 1) {
                throw new IllegalStateException(
                        "type parameters: " + typeParameters + ", expected exactly one");
            }
        }
        keyType = refKey ? typeParameters.get(0) : null;
        valueType = refValue ? typeParameters.get(typeParameters.size() - 1) : null;
    } else {
        // `type` is a raw type
        keyType = TypeFactory.unknownType();
        valueType = TypeFactory.unknownType();
    }
    return MapDeserializer.create(keyType, valueType, typeHandlerPair, finish);
}
 
Example 8
Source File: BeanProperty.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JavaType getType() {
    return TypeFactory.unknownType();
}
 
Example 9
Source File: UntypedObjectDeserializer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * We need to implement this method to properly find things to delegate
 * to: it cannot be done earlier since delegated deserializers almost
 * certainly require access to this instance (at least "List" and "Map" ones)
 */
@SuppressWarnings("unchecked")
@Override
public void resolve(DeserializationContext ctxt) throws JsonMappingException
{
    JavaType obType = ctxt.constructType(Object.class);
    JavaType stringType = ctxt.constructType(String.class);
    TypeFactory tf = ctxt.getTypeFactory();

    /* 26-Nov-2014, tatu: This is highly unusual, as in general contextualization
     *    should always be called separately, from within "createContextual()".
     *    But this is a very singular deserializer since it operates on `Object`
     *    (and often for `?` type parameter), and as a result, easily and commonly
     *    results in cycles, being value deserializer for various Maps and Collections.
     *    Because of this, we must somehow break the cycles. This is done here by
     *    forcing pseudo-contextualization with null property.
     */

    // So: first find possible custom instances
    if (_listType == null) {
        _listDeserializer = _clearIfStdImpl(_findCustomDeser(ctxt, tf.constructCollectionType(List.class, obType)));
    } else {
        // NOTE: if non-default List type, always consider to be non-standard deser
        _listDeserializer = _findCustomDeser(ctxt, _listType);
    }
    if (_mapType == null) {
        _mapDeserializer = _clearIfStdImpl(_findCustomDeser(ctxt, tf.constructMapType(Map.class, stringType, obType)));
    } else {
        // NOTE: if non-default Map type, always consider to be non-standard deser
        _mapDeserializer = _findCustomDeser(ctxt, _mapType);
    }
    _stringDeserializer = _clearIfStdImpl(_findCustomDeser(ctxt, stringType));
    _numberDeserializer = _clearIfStdImpl(_findCustomDeser(ctxt, tf.constructType(Number.class)));

    // and then do bogus contextualization, in case custom ones need to resolve dependencies of
    // their own
    JavaType unknown = TypeFactory.unknownType();
    _mapDeserializer = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(_mapDeserializer, null, unknown);
    _listDeserializer = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(_listDeserializer, null, unknown);
    _stringDeserializer = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(_stringDeserializer, null, unknown);
    _numberDeserializer = (JsonDeserializer<Object>) ctxt.handleSecondaryContextualization(_numberDeserializer, null, unknown);
}
 
Example 10
Source File: CustomTypeIdResolver.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
public CustomTypeIdResolver() {
    super(TypeFactory.unknownType(), null);
}
 
Example 11
Source File: JavaType.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Convenience method that is functionally same as:
 *<code>
 * JavaType t = containedType(index);
 * if (t == null) {
 *    t = TypeFactory.unknownType();
 * }
 *</code>
 * and typically used to eliminate need for null checks for common case
 * where we just want to check if containedType is available first; and
 * if not, use "unknown type" (which translates to <code>java.lang.Object</code>
 * basically).
 *
 * @since 2.5
 */
public JavaType containedTypeOrUnknown(int index) {
    JavaType t = containedType(index);
    return (t == null)  ? TypeFactory.unknownType() : t;
}
 
Example 12
Source File: OptimizedValueInstantiator.java    From jackson-modules-base with Apache License 2.0 2 votes vote down vote up
/**
 * Default constructor which is only used when creating
 * dummy instance to call factory method.
 */
protected OptimizedValueInstantiator() {
    super(/*DeserializationConfig*/null, TypeFactory.unknownType());
}