public JavaType typeFromId(String s) { return TypeFactory.defaultInstance().constructFromCanonical(s); }
return ctxt.getTypeFactory().constructFromCanonical(value); case STD_CURRENCY:
JavaType t = getTypeFactory().constructFromCanonical(subClass); if (t.isTypeOrSubTypeOf(baseType.getRawClass())) { return t;
protected Object deserializeJsonObject(String className, byte[] data) { try { JavaType type = TypeFactory.defaultInstance().constructFromCanonical(className); return objectMapper.readValue(new String(data, Charset.forName("UTF-8")), type); } catch(Exception e) { throw new InvalidRequestException(Status.INTERNAL_SERVER_ERROR, "Could not deserialize JSON object: "+e.getMessage()); } }
protected Object deserializeJsonObject(String className, byte[] data) { try { JavaType type = TypeFactory.defaultInstance().constructFromCanonical(className); return objectMapper.readValue(new String(data, Charset.forName("UTF-8")), type); } catch(Exception e) { throw new InvalidRequestException(Status.INTERNAL_SERVER_ERROR, "Could not deserialize JSON object: "+e.getMessage()); } }
@Override public JavaType convert(SwaggerToClassGenerator swaggerToClassGenerator, Object def) { Map<String, Object> vendorExtensions = findVendorExtensions(def); String canonical = ClassUtils.getClassName(vendorExtensions); if (!StringUtils.isEmpty(canonical)) { try { return swaggerToClassGenerator.getTypeFactory().constructFromCanonical(canonical); } catch (Throwable e) { // ignore this } } return doConvert(swaggerToClassGenerator, def); } }
protected Object deserializeJsonObject(String className, byte[] data) { try { JavaType type = TypeFactory.defaultInstance().constructFromCanonical(className); return objectMapper.readValue(new String(data, Charset.forName("UTF-8")), type); } catch(Exception e) { throw new InvalidRequestException(Status.INTERNAL_SERVER_ERROR, "Could not deserialize JSON object: "+e.getMessage()); } }
public JavaType typeFromId(String id) { /* 30-Jan-2010, tatu: Most ids are basic class names; so let's first * check if any generics info is added; and only then ask factory * to do translation when necessary */ if (id.indexOf('<') > 0) { JavaType t = _typeFactory.constructFromCanonical(id); // note: may want to try combining with specialization (esp for EnumMap)? return t; } try { Class<?> cls = ClassUtil.findClass(id); return _typeFactory.constructSpecializedType(_baseType, cls); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): no such class found"); } catch (Exception e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): "+e.getMessage(), e); } }
public JavaType typeFromId(String id) { /* 30-Jan-2010, tatu: Most ids are basic class names; so let's first * check if any generics info is added; and only then ask factory * to do translation when necessary */ if (id.indexOf('<') > 0) { JavaType t = _typeFactory.constructFromCanonical(id); // note: may want to try combining with specialization (esp for EnumMap)? return t; } try { Class<?> cls = ClassUtil.findClass(id); return _typeFactory.constructSpecializedType(_baseType, cls); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): no such class found"); } catch (Exception e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): "+e.getMessage(), e); } }
protected JavaType _typeFromId(String id, TypeFactory typeFactory) { /* 30-Jan-2010, tatu: Most ids are basic class names; so let's first * check if any generics info is added; and only then ask factory * to do translation when necessary */ if (id.indexOf('<') > 0) { JavaType t = typeFactory.constructFromCanonical(id); // note: may want to try combining with specialization (esp for EnumMap)? return t; } try { Class<?> cls = ClassUtil.findClass(id); return typeFactory.constructSpecializedType(_baseType, cls); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): no such class found"); } catch (Exception e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): "+e.getMessage(), e); } }
<T> Map<String, T> loadProps(Class<?> clazz, Function<KvProperty, T> func) { ImmutableMap.Builder<String, T> b = ImmutableMap.builder(); TypeFactory tf = TypeFactory.defaultInstance(); while(clazz != null && !Object.class.equals(clazz)) { for(Field field: clazz.getDeclaredFields()) { KvMapping mapping = field.getAnnotation(KvMapping.class); if(mapping == null) { continue; } JavaType javaType; String typeStr = mapping.type(); if(!typeStr.isEmpty()) { javaType = tf.constructFromCanonical(typeStr); } else { javaType = tf.constructType(field.getGenericType()); } KvProperty property = new KvProperty(this, field.getName(), field, javaType); b.put(property.getKey(), func.apply(property)); } clazz = clazz.getSuperclass(); } return b.build(); }
protected JavaType _typeFromId(String id, TypeFactory typeFactory) { /* 30-Jan-2010, tatu: Most ids are basic class names; so let's first * check if any generics info is added; and only then ask factory * to do translation when necessary */ if (id.indexOf('<') > 0) { JavaType t = typeFactory.constructFromCanonical(id); // note: may want to try combining with specialization (esp for EnumMap)? return t; } try { Class<?> cls = ClassUtil.findClass(id); return typeFactory.constructSpecializedType(_baseType, cls); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): no such class found"); } catch (Exception e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): "+e.getMessage(), e); } }
@Override public JavaType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken curr = jp.getCurrentToken(); // Usually should just get string value: if (curr == JsonToken.VALUE_STRING) { String str = jp.getText().trim(); if (str.length() == 0) { return getEmptyValue(); } return ctxt.getTypeFactory().constructFromCanonical(str); } // or occasionally just embedded object maybe if (curr == JsonToken.VALUE_EMBEDDED_OBJECT) { return (JavaType) jp.getEmbeddedObject(); } throw ctxt.mappingException(_valueClass); } }
@Override public JavaType deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken curr = jp.getCurrentToken(); // Usually should just get string value: if (curr == JsonToken.VALUE_STRING) { String str = jp.getText().trim(); if (str.length() == 0) { return getEmptyValue(); } return ctxt.getTypeFactory().constructFromCanonical(str); } // or occasionally just embedded object maybe if (curr == JsonToken.VALUE_EMBEDDED_OBJECT) { return (JavaType) jp.getEmbeddedObject(); } throw ctxt.mappingException(_valueClass); } }
return ctxt.getTypeFactory().constructFromCanonical(value); case STD_CURRENCY:
return ctxt.getTypeFactory().constructFromCanonical(value); case STD_CURRENCY:
protected JavaType _typeFromId(String id, DatabindContext ctxt) throws IOException { /* 30-Jan-2010, tatu: Most ids are basic class names; so let's first * check if any generics info is added; and only then ask factory * to do translation when necessary */ TypeFactory tf = ctxt.getTypeFactory(); if (id.indexOf('<') > 0) { // note: may want to try combining with specialization (esp for EnumMap)? return tf.constructFromCanonical(id); } Class<?> cls; try { cls = tf.findClass(id); } catch (ClassNotFoundException e) { // 24-May-2016, tatu: Ok, this is pretty ugly, but we should always get // DeserializationContext, just playing it safe if (ctxt instanceof DeserializationContext) { DeserializationContext dctxt = (DeserializationContext) ctxt; // First: we may have problem handlers that can deal with it? return dctxt.handleUnknownTypeId(_baseType, id, this, "no such class found"); } // ... meaning that we really should never get here. return null; } catch (Exception e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): "+e.getMessage(), e); } return tf.constructSpecializedType(_baseType, cls); }
return ctxt.getTypeFactory().constructFromCanonical(value); case STD_CURRENCY:
@Override public JavaType convert(SwaggerToClassGenerator swaggerToClassGenerator, Object def) { Map<String, Object> vendorExtensions = findVendorExtensions(def); String canonical = ClassUtils.getClassName(vendorExtensions); if (!StringUtils.isEmpty(canonical)) { try { return swaggerToClassGenerator.getTypeFactory().constructFromCanonical(canonical); } catch (Throwable e) { // ignore this } } return doConvert(swaggerToClassGenerator, def); } }
JavaType t = getTypeFactory().constructFromCanonical(subClass); if (t.isTypeOrSubTypeOf(baseType.getRawClass())) { return t;