in hollow/src/main/java/com/netflix/hollow/core/write/objectmapper/HollowObjectTypeMapper.java [360:435]
private MappedField(Field f, Set<Type> visitedTypes) {
this.fieldOffset = unsafe.objectFieldOffset(f);
this.fieldName = f.getName();
this.type = f.getGenericType();
this.typeNameAnnotation = f.getAnnotation(HollowTypeName.class);
this.hashKeyAnnotation = f.getAnnotation(HollowHashKey.class);
this.numShardsAnnotation = f.getAnnotation(HollowShardLargeType.class);
this.isInlinedField = f.isAnnotationPresent(HollowInline.class);
HollowTypeMapper subTypeMapper = null;
if(type == int.class) {
fieldType = MappedFieldType.INT;
} else if(type == short.class) {
fieldType = MappedFieldType.SHORT;
} else if(type == byte.class) {
fieldType = MappedFieldType.BYTE;
} else if(type == char.class) {
fieldType = MappedFieldType.CHAR;
} else if(type == long.class) {
fieldType = MappedFieldType.LONG;
} else if(type == boolean.class) {
fieldType = MappedFieldType.BOOLEAN;
} else if(type == float.class) {
fieldType = MappedFieldType.FLOAT;
} else if(type == double.class) {
fieldType = MappedFieldType.DOUBLE;
} else if (type == byte[].class && clazz == String.class) {
fieldType = MappedFieldType.STRING;
} else if(type == byte[].class) {
fieldType = MappedFieldType.BYTES;
} else if(type == char[].class) {
fieldType = MappedFieldType.STRING;
} else if(isInlinedField && type == Integer.class) {
fieldType = MappedFieldType.INLINED_INT;
} else if(isInlinedField && type == Short.class) {
fieldType = MappedFieldType.INLINED_SHORT;
} else if(isInlinedField && type == Byte.class) {
fieldType = MappedFieldType.INLINED_BYTE;
} else if(isInlinedField && type == Character.class) {
fieldType = MappedFieldType.INLINED_CHAR;
} else if(isInlinedField && type == Long.class) {
fieldType = MappedFieldType.INLINED_LONG;
} else if(isInlinedField && type == Boolean.class) {
fieldType = MappedFieldType.INLINED_BOOLEAN;
} else if(isInlinedField && type == Float.class) {
fieldType = MappedFieldType.INLINED_FLOAT;
} else if(isInlinedField && type == Double.class) {
fieldType = MappedFieldType.INLINED_DOUBLE;
} else if(isInlinedField && type == String.class) {
fieldType = MappedFieldType.INLINED_STRING;
} else if(type == NullablePrimitiveBoolean.class) {
fieldType = MappedFieldType.NULLABLE_PRIMITIVE_BOOLEAN;
} else {
if(isInlinedField)
throw new IllegalStateException("@HollowInline annotation defined on field " + f + ", which is not either a String or boxed primitive.");
fieldType = MappedFieldType.REFERENCE;
if(visitedTypes.contains(this.type)){
throw new IllegalStateException("circular reference detected on field " + f + "; this type of relationship is not supported");
}
// guard recursion here
visitedTypes.add(this.type);
subTypeMapper = parentMapper.getTypeMapper(type,
typeNameAnnotation != null ? typeNameAnnotation.name() : null,
hashKeyAnnotation != null ? hashKeyAnnotation.fields() : null,
numShardsAnnotation != null ? numShardsAnnotation.numShards() : -1,
visitedTypes);
// once we've safely returned from a leaf node in recursion, we can remove this MappedField's type
visitedTypes.remove(this.type);
}
this.subTypeMapper = subTypeMapper;
}