com.google.api.client.util.FieldInfo

Here are the examples of the java api class com.google.api.client.util.FieldInfo taken from open source projects.

1. HttpHeaders#parseHeader()

Project: google-http-java-client
File: HttpHeaders.java
/** Parses the specified case-insensitive header pair into this HttpHeaders instance. */
void parseHeader(String headerName, String headerValue, ParseHeaderState state) {
    List<Type> context = state.context;
    ClassInfo classInfo = state.classInfo;
    ArrayValueMap arrayValueMap = state.arrayValueMap;
    StringBuilder logger = state.logger;
    if (logger != null) {
        logger.append(headerName + ": " + headerValue).append(StringUtils.LINE_SEPARATOR);
    }
    // use field information if available
    FieldInfo fieldInfo = classInfo.getFieldInfo(headerName);
    if (fieldInfo != null) {
        Type type = Data.resolveWildcardTypeOrTypeVariable(context, fieldInfo.getGenericType());
        // type is now class, parameterized type, or generic array type
        if (Types.isArray(type)) {
            // array that can handle repeating values
            Class<?> rawArrayComponentType = Types.getRawArrayComponentType(context, Types.getArrayComponentType(type));
            arrayValueMap.put(fieldInfo.getField(), rawArrayComponentType, parseValue(rawArrayComponentType, context, headerValue));
        } else if (Types.isAssignableToOrFrom(Types.getRawArrayComponentType(context, type), Iterable.class)) {
            // iterable that can handle repeating values
            @SuppressWarnings("unchecked") Collection<Object> collection = (Collection<Object>) fieldInfo.getValue(this);
            if (collection == null) {
                collection = Data.newCollectionInstance(type);
                fieldInfo.setValue(this, collection);
            }
            Type subFieldType = type == Object.class ? null : Types.getIterableParameter(type);
            collection.add(parseValue(subFieldType, context, headerValue));
        } else {
            // parse value based on field type
            fieldInfo.setValue(this, parseValue(type, context, headerValue));
        }
    } else {
        // store header values in an array list
        @SuppressWarnings("unchecked") ArrayList<String> listValue = (ArrayList<String>) this.get(headerName);
        if (listValue == null) {
            listValue = new ArrayList<String>();
            this.set(headerName, listValue);
        }
        listValue.add(headerValue);
    }
}