Java Code Examples for com.fasterxml.jackson.databind.JavaType#isCollectionLikeType()
The following examples show how to use
com.fasterxml.jackson.databind.JavaType#isCollectionLikeType() .
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: CustomMessageElementVisitor.java From caravan with Apache License 2.0 | 6 votes |
protected FieldElement buildFieldElement(BeanProperty writer, Label label) throws JsonMappingException { FieldElement.Builder fBuilder = FieldElement.builder(); fBuilder.name(writer.getName()); fBuilder.tag(nextTag(writer)); JavaType type = writer.getType(); if (type.isArrayType() && type.getContentType().getRawClass() == byte.class) { fBuilder.label(label); fBuilder.type(ScalarType.BYTES); } else if (type.isArrayType() || type.isCollectionLikeType()) { fBuilder.label(Label.REPEATED); fBuilder.type(getDataType(type.getContentType())); } else if (type instanceof MapType) { Class<?> wrapperClass = DynamicClassFactory.INSTANCE.fetchOrCreatePairClass((MapType) type); fBuilder.label(Label.REPEATED); fBuilder.type(getDataType(SimpleType.constructUnsafe(wrapperClass))); } else { fBuilder.label(label); fBuilder.type(getDataType(type)); } return fBuilder.build(); }
Example 2
Source File: TypeUtil.java From spring-auto-restdocs with Apache License 2.0 | 5 votes |
public static List<JavaType> resolveAllTypes(JavaType javaType, TypeFactory typeFactory, TypeMapping typeMapping) { if (javaType.isCollectionLikeType() || javaType.isArrayType()) { return resolveArrayTypes(javaType.getContentType(), typeFactory, typeMapping); } else { return resolveNonArrayTypes(javaType, typeFactory, typeMapping); } }
Example 3
Source File: NsTypeResolverBuilder.java From components with Apache License 2.0 | 5 votes |
@Override public boolean useForType(JavaType t) { if (t.isCollectionLikeType()) { return false; } if (t.getRawClass() == XMLGregorianCalendar.class) { return false; } return super.useForType(t); }
Example 4
Source File: TypeFactory.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Factory method for creating a subtype of given base type, as defined * by specified subclass; but retaining generic type information if any. * Can be used, for example, to get equivalent of "HashMap<String,Integer>" * from "Map<String,Integer>" by giving <code>HashMap.class</code> * as subclass. */ public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass) { // simple optimization to avoid costly introspection if type-erased type does NOT differ final Class<?> rawBase = baseType.getRawClass(); if (rawBase == subclass) { return baseType; } JavaType newType; // also: if we start from untyped, not much to save do { // bogus loop to be able to break if (rawBase == Object.class) { newType = _fromClass(null, subclass, EMPTY_BINDINGS); break; } if (!rawBase.isAssignableFrom(subclass)) { throw new IllegalArgumentException(String.format( "Class %s not subtype of %s", subclass.getName(), baseType)); } // A few special cases where we can simplify handling: // (1) Original target type has no generics -- just resolve subtype if (baseType.getBindings().isEmpty()) { newType = _fromClass(null, subclass, EMPTY_BINDINGS); break; } // (2) A small set of "well-known" List/Map subtypes where can take a short-cut if (baseType.isContainerType()) { if (baseType.isMapLikeType()) { if ((subclass == HashMap.class) || (subclass == LinkedHashMap.class) || (subclass == EnumMap.class) || (subclass == TreeMap.class)) { newType = _fromClass(null, subclass, TypeBindings.create(subclass, baseType.getKeyType(), baseType.getContentType())); break; } } else if (baseType.isCollectionLikeType()) { if ((subclass == ArrayList.class) || (subclass == LinkedList.class) || (subclass == HashSet.class) || (subclass == TreeSet.class)) { newType = _fromClass(null, subclass, TypeBindings.create(subclass, baseType.getContentType())); break; } // 29-Oct-2015, tatu: One further shortcut: there are variants of `EnumSet`, // but they are impl details and we basically do not care... if (rawBase == EnumSet.class) { return baseType; } } } // (3) Sub-class does not take type parameters -- just resolve subtype int typeParamCount = subclass.getTypeParameters().length; if (typeParamCount == 0) { newType = _fromClass(null, subclass, EMPTY_BINDINGS); break; } // (4) If all else fails, do the full traversal using placeholders TypeBindings tb = _bindingsForSubtype(baseType, typeParamCount, subclass); newType = _fromClass(null, subclass, tb); } while (false); // 25-Sep-2016, tatu: As per [databind#1384] also need to ensure handlers get // copied as well newType = newType.withHandlersFrom(baseType); return newType; }
Example 5
Source File: StreamSpliterator.java From riptide with MIT License | 4 votes |
StreamSpliterator(final JavaType type, final JsonParser parser) { this.type = type; this.parser = parser; this.isNotStreamOfArrays = !type.isArrayType() && !type.isCollectionLikeType(); }