本文整理汇总了Java中org.codehaus.jackson.map.type.TypeFactory类的典型用法代码示例。如果您正苦于以下问题:Java TypeFactory类的具体用法?Java TypeFactory怎么用?Java TypeFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeFactory类属于org.codehaus.jackson.map.type包,在下文中一共展示了TypeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructList
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
/**
* Constructs the object based on the content as a List, the JSON can be an array or just a single value without the [] symbols
* @param content Reader
* @return A collection of the specified type
* @throws IOException
*/
public <T> List<T> constructList(Reader content, Class<T> requiredType) throws IOException, JsonMappingException, JsonParseException
{
ObjectReader reader = objectMapper.reader(TypeFactory.defaultInstance().constructParametricType(List.class, requiredType));
try
{
List<T> toReturn = reader.readValue(content);
if (toReturn == null || toReturn.isEmpty())
{
throw new InvalidArgumentException("Could not read content from HTTP request body, the list is empty");
}
return toReturn;
}
catch (IOException error)
{
throw new InvalidArgumentException("Could not read content from HTTP request body: "+error.getMessage());
}
}
示例2: getJavaTypeForMessage
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
/**
* Determine a Jackson JavaType for the given JMS Message,
* typically parsing a type id message property.
* <p>The default implementation parses the configured type id property name
* and consults the configured type id mapping. This can be overridden with
* a different strategy, e.g. doing some heuristics based on message origin.
* @param message the JMS Message to set the type id on
* @throws JMSException if thrown by JMS methods
* @see #setTypeIdOnMessage(Object, javax.jms.Message)
* @see #setTypeIdPropertyName(String)
* @see #setTypeIdMappings(java.util.Map)
*/
protected JavaType getJavaTypeForMessage(Message message) throws JMSException {
String typeId = message.getStringProperty(this.typeIdPropertyName);
if (typeId == null) {
throw new MessageConversionException("Could not find type id property [" + this.typeIdPropertyName + "]");
}
Class<?> mappedClass = this.idClassMappings.get(typeId);
if (mappedClass != null) {
return TypeFactory.type(mappedClass);
}
try {
Class<?> typeClass = ClassUtils.forName(typeId, this.beanClassLoader);
return TypeFactory.type(typeClass);
}
catch (Throwable ex) {
throw new MessageConversionException("Failed to resolve type id [" + typeId + "]", ex);
}
}
示例3: typeFromId
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
public JavaType typeFromId(String paramString)
{
if (paramString.indexOf('<') > 0)
return TypeFactory.fromCanonical(paramString);
try
{
Class localClass = Class.forName(paramString, true, Thread.currentThread().getContextClassLoader());
JavaType localJavaType = this._typeFactory.constructSpecializedType(this._baseType, localClass);
return localJavaType;
}
catch (ClassNotFoundException localClassNotFoundException)
{
throw new IllegalArgumentException("Invalid type id '" + paramString + "' (for id type 'Id.class'): no such class found");
}
catch (Exception localException)
{
}
throw new IllegalArgumentException("Invalid type id '" + paramString + "' (for id type 'Id.class'): " + localException.getMessage(), localException);
}
示例4: getType
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
protected JavaType getType(TypeBindings paramTypeBindings, TypeVariable<?>[] paramArrayOfTypeVariable)
{
if ((paramArrayOfTypeVariable != null) && (paramArrayOfTypeVariable.length > 0))
{
paramTypeBindings = paramTypeBindings.childInstance();
int i = paramArrayOfTypeVariable.length;
int j = 0;
if (j < i)
{
TypeVariable<?> localTypeVariable = paramArrayOfTypeVariable[j];
paramTypeBindings._addPlaceholder(localTypeVariable.getName());
Type localType = localTypeVariable.getBounds()[0];
if (localType == null);
for (JavaType localJavaType = TypeFactory.unknownType(); ; localJavaType = paramTypeBindings.resolveType(localType))
{
paramTypeBindings.addBinding(localTypeVariable.getName(), localJavaType);
j++;
break;
}
}
}
return paramTypeBindings.resolveType(getGenericType());
}
示例5: findStdBeanDeserializer
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
protected JsonDeserializer<Object> findStdBeanDeserializer(DeserializationConfig paramDeserializationConfig, DeserializerProvider paramDeserializerProvider, JavaType paramJavaType, BeanProperty paramBeanProperty)
throws JsonMappingException
{
JsonDeserializer localJsonDeserializer1 = (JsonDeserializer)_simpleDeserializers.get(paramJavaType);
if (localJsonDeserializer1 != null)
return localJsonDeserializer1;
if (AtomicReference.class.isAssignableFrom(paramJavaType.getRawClass()))
{
JavaType[] arrayOfJavaType = paramDeserializationConfig.getTypeFactory().findTypeParameters(paramJavaType, AtomicReference.class);
if ((arrayOfJavaType == null) || (arrayOfJavaType.length < 1));
for (JavaType localJavaType = TypeFactory.unknownType(); ; localJavaType = arrayOfJavaType[0])
return new StdDeserializer.AtomicReferenceDeserializer(localJavaType, paramBeanProperty);
}
JsonDeserializer localJsonDeserializer2 = this.optionalHandlers.findDeserializer(paramJavaType, paramDeserializationConfig, paramDeserializerProvider);
if (localJsonDeserializer2 != null)
return localJsonDeserializer2;
return null;
}
示例6: getSchema
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("array", true);
if (typeHint != null) {
JavaType javaType = TypeFactory.type(typeHint);
if (javaType.isArrayType()) {
Class<?> componentType = ((ArrayType) javaType).getContentType().getRawClass();
JsonSerializer<Object> ser = provider.findValueSerializer(componentType);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(provider, null) :
JsonSchema.getDefaultSchemaNode();
o.put("items", schemaNode);
}
}
return o;
}
示例7: resolve
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
/**
* We can try to find the actual serializer for value, if we can
* statically figure out what the result type must be.
*/
public void resolve(SerializerProvider provider)
throws JsonMappingException
{
if (_valueSerializer == null) {
/* Note: we can only assign serializer statically if the
* declared type is final -- if not, we don't really know
* the actual type until we get the instance.
*/
// 10-Mar-2010, tatu: Except if static typing is to be used
if (provider.isEnabled(SerializationConfig.Feature.USE_STATIC_TYPING)
|| Modifier.isFinal(_accessorMethod.getReturnType().getModifiers())) {
JavaType t = TypeFactory.type(_accessorMethod.getGenericReturnType());
// false -> no need to cache
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
_valueSerializer = provider.findTypedValueSerializer(t, false);
}
}
}
示例8: construct
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
/**
* Factory method used to construct Map serializers.
*
* @param ignoredList Array of entry names that are to be filtered on
* serialization; null if none
* @param mapType Declared type information (needed for static typing)
* @param staticValueType Whether static typing should be used for the
* Map (which includes its contents)
* @param vts Type serializer to use for map entry values, if any
*/
public static MapSerializer construct(String[] ignoredList, JavaType mapType,
boolean staticValueType, TypeSerializer vts)
{
HashSet<String> ignoredEntries = toSet(ignoredList);
JavaType valueType = (mapType == null) ? TypeFactory.type(Object.class) : mapType.getContentType();
// If value type is final, it's same as forcing static value typing:
if (!staticValueType) {
staticValueType = (valueType != null && valueType.isFinal());
}
/* for plain vanilla case can return singleton; plain meaning that there are
* no ignored entries (no view), non-static type (can not statically determine
* value serializer) and no assigned value type serializer.
*/
if (!staticValueType && (ignoredEntries == null) && (vts == null)) {
return instance;
}
return new MapSerializer(ignoredEntries, valueType, staticValueType, vts);
}
示例9: _createAndCacheUntypedSerializer
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
/**
* Method that will try to construct a value serializer; and if
* one is succesfully created, cache it for reuse.
*/
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> type)
throws JsonMappingException
{
JsonSerializer<Object> ser;
try {
ser = _createUntypedSerializer(TypeFactory.type(type));
} catch (IllegalArgumentException iae) {
/* We better only expose checked exceptions, since those
* are what caller is expected to handle
*/
throw new JsonMappingException(iae.getMessage(), null, iae);
}
if (ser != null) {
_serializerCache.addNonTypedSerializer(type, ser);
/* Finally: some serializers want to do post-processing, after
* getting registered (to handle cyclic deps).
*/
if (ser instanceof ResolvableSerializer) {
_resolveSerializer((ResolvableSerializer)ser);
}
}
return ser;
}
示例10: getSchema
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode objectNode = createSchemaNode("string", true);
if (typeHint != null) {
JavaType type = TypeFactory.type(typeHint);
if (type.isEnumType()) {
ArrayNode enumNode = objectNode.putArray("enum");
for (String value : _values.values()) {
enumNode.add(value);
}
}
}
return objectNode;
}
示例11: findSerializationType
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
/**
* Method that will try to determine statically defined type of property
* being serialized, based on annotations (for overrides), and alternatively
* declared type (if static typing for serialization is enabled).
* If neither can be used (no annotations, dynamic typing), returns null.
*/
protected JavaType findSerializationType(Annotated a, boolean useStaticTyping)
{
// [JACKSON-120]: Check to see if serialization type is fixed
Class<?> serializationType = _annotationIntrospector.findSerializationType(a);
if (serializationType != null) {
// Must be a super type...
Class<?> raw = a.getRawType();
if (!serializationType.isAssignableFrom(raw)) {
throw new IllegalArgumentException("Illegal concrete-type annotation for method '"+a.getName()+"': class "+serializationType.getName()+" not a super-type of (declared) class "+raw.getName());
}
return TypeFactory.type(serializationType);
}
/* [JACKSON-114]: if using static typing, declared type is known
* to be the type...
*/
JsonSerialize.Typing typing = _annotationIntrospector.findSerializationTyping(a);
if (typing != null) {
useStaticTyping = (typing == JsonSerialize.Typing.STATIC);
}
if (useStaticTyping) {
return TypeFactory.type(a.getGenericType());
}
return null;
}
示例12: getSchema
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("object", true);
if (typeHint instanceof ParameterizedType) {
Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments();
if (typeArgs.length == 2) {
JavaType enumType = TypeFactory.type(typeArgs[0]);
JavaType valueType = TypeFactory.type(typeArgs[1]);
ObjectNode propsNode = JsonNodeFactory.instance.objectNode();
Class<Enum<?>> enumClass = (Class<Enum<?>>) enumType.getRawClass();
for (Enum<?> enumValue : enumClass.getEnumConstants()) {
JsonSerializer<Object> ser = provider.findValueSerializer(valueType.getRawClass());
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(provider, null) :
JsonSchema.getDefaultSchemaNode();
propsNode.put(provider.getConfig().getAnnotationIntrospector().findEnumValue((Enum<?>)enumValue), schemaNode);
}
o.put("properties", propsNode);
}
}
return o;
}
示例13: forSerialization
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
public BasicBeanDescription forSerialization(SerializationConfig cfg,
Class<?> c,
MixInResolver r)
{
AnnotationIntrospector ai = cfg.getAnnotationIntrospector();
AnnotatedClass ac = AnnotatedClass.construct(c, ai, r);
// False -> no need to collect ignorable member list
ac.resolveMemberMethods(getSerializationMethodFilter(cfg), false);
/* only the default constructor needed here (that's needed
* in case we need to check default bean property values,
* to omit them)
*/
/* 31-Oct-2009, tatus: Actually, creator info will come in handy
* for resolving [JACKSON-170] as well
*/
ac.resolveCreators(true);
// False -> no need to collect ignorable field list
ac.resolveFields(false);
return new BasicBeanDescription(TypeFactory.type(c), ac, ai);
}
示例14: typeFromId
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
public JavaType typeFromId(String paramString)
{
if (paramString.indexOf('<') > 0)
return TypeFactory.fromCanonical(paramString);
try
{
Class localClass = Class.forName(paramString, true, Thread.currentThread().getContextClassLoader());
JavaType localJavaType = this._typeFactory.constructSpecializedType(this._baseType, localClass);
return localJavaType;
}
catch (ClassNotFoundException localClassNotFoundException)
{
throw new IllegalArgumentException("Invalid type id '" + paramString + "' (for id type 'Id.class'): no such class found");
}
catch (Exception localException)
{
throw new IllegalArgumentException("Invalid type id '" + paramString + "' (for id type 'Id.class'): " + localException.getMessage(), localException);
}
}
示例15: findStdBeanDeserializer
import org.codehaus.jackson.map.type.TypeFactory; //导入依赖的package包/类
protected JsonDeserializer<Object> findStdBeanDeserializer(DeserializationConfig paramDeserializationConfig, DeserializerProvider paramDeserializerProvider, JavaType paramJavaType, BeanProperty paramBeanProperty)
{
Class localClass = paramJavaType.getRawClass();
JsonDeserializer localJsonDeserializer = (JsonDeserializer)_simpleDeserializers.get(new ClassKey(localClass));
if (localJsonDeserializer != null);
do
{
return localJsonDeserializer;
if (AtomicReference.class.isAssignableFrom(localClass))
{
JavaType[] arrayOfJavaType = paramDeserializationConfig.getTypeFactory().findTypeParameters(paramJavaType, AtomicReference.class);
if ((arrayOfJavaType == null) || (arrayOfJavaType.length <= 0));
for (JavaType localJavaType = TypeFactory.unknownType(); ; localJavaType = arrayOfJavaType[0])
return new AtomicReferenceDeserializer(localJavaType, paramBeanProperty);
}
localJsonDeserializer = this.optionalHandlers.findDeserializer(paramJavaType, paramDeserializationConfig, paramDeserializerProvider);
}
while (localJsonDeserializer != null);
return null;
}