/** * @param type the property type * @return true if a byte array */ private boolean isByteArray(final Type type) { boolean ret = type instanceof Class && type == byte[].class; if (!ret && type instanceof ArrayType) { ArrayType at = (ArrayType) type; JavaType contentType = at.getContentType(); if (contentType instanceof SimpleType) { SimpleType st = (SimpleType) contentType; ret = st.getRawClass() == byte.class; } } return ret; } }
public static String createSignature(SimpleType simpleType) { List<Class<?>> parameterClasses = null; try { Field typeParametersField = simpleType.getClass().getDeclaredField("_typeParameters"); typeParametersField.setAccessible(true); JavaType[] typeParameters = (JavaType[]) typeParametersField.get(simpleType); parameterClasses = new ArrayList<Class<?>>(); if (typeParameters != null) { for (JavaType javaType : typeParameters) { parameterClasses.add(javaType.getRawClass()); } } } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } return ModelUtil.getSimpleTypeSignature(simpleType.getRawClass(), parameterClasses); }
/** * From Jackson type creates a JRAPIDoc type, type is stored in cache * * @param jacksonType * @return */ public Type getType(SimpleType jacksonType) { try { String signature = JacksonSignature.createSignature(jacksonType); CustomType type = new CustomType(jacksonType.getRawClass().getName(), signature, jacksonType.getRawClass()); if (cache.containsKey(signature)) { return cache.get(signature); } cache.put(signature, type); ObjectWriter objectWriter = objectMapper.writerFor(jacksonType); Field prefetchField = objectWriter.getClass().getDeclaredField("_prefetch"); prefetchField.setAccessible(true); ObjectWriter.Prefetch prefetch = (ObjectWriter.Prefetch) prefetchField.get(objectWriter); doIntrospection(prefetch.valueSerializer, type); return type; } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }
@Override public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) { if (type instanceof SimpleType) { SimpleType simpleType = (SimpleType) type; Class<?> valueType = extractValueTypeIfAnnotatedWithXmlJavaTypeAdapter(simpleType.getRawClass()); if (valueType != null) { return context.resolve(valueType); } } return chain.next().resolve(type, context, chain); }
@Override public Model resolve(Type type, ModelConverterContext context, Iterator<ModelConverter> chain) { if (type instanceof SimpleType) { SimpleType simpleType = (SimpleType) type; Class<?> valueType = extractValueTypeIfAnnotatedWithXmlJavaTypeAdapter(simpleType.getRawClass()); if (valueType != null) { return context.resolve(valueType); } } return chain.next().resolve(type, context, chain); }
Class c = null; if (type instanceof SimpleType) { c = ((SimpleType) type).getRawClass(); } else if (type instanceof Class) { c = (Class) type;
Class c = null; if (type instanceof SimpleType) { c = ((SimpleType) type).getRawClass(); } else if (type instanceof Class) { c = (Class) type;
@Override public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { if (annotations != null) { for (Annotation annotation : annotations) { if (annotation instanceof XmlTransient) { return null; } } } if (type instanceof SimpleType) { SimpleType simpleType = (SimpleType) type; Class<?> valueType = extractValueTypeIfAnnotatedWithXmlJavaTypeAdapter(simpleType.getRawClass()); if (valueType != null) { return context.resolveProperty(valueType, annotations); } } return chain.next().resolveProperty(type, context, annotations, chain); } }
@Override public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) { if (annotations != null) { for (Annotation annotation : annotations) { if (annotation instanceof XmlTransient) { return null; } } } if (type instanceof SimpleType) { SimpleType simpleType = (SimpleType) type; Class<?> valueType = extractValueTypeIfAnnotatedWithXmlJavaTypeAdapter(simpleType.getRawClass()); if (valueType != null) { return context.resolveProperty(valueType, annotations); } } return chain.next().resolveProperty(type, context, annotations, chain); } }
type = ((SimpleType) type).getRawClass();