Java Code Examples for com.google.gson.internal.Primitives#isWrapperType()
The following examples show how to use
com.google.gson.internal.Primitives#isWrapperType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GsonBuilder.java From letv with Apache License 2.0 | 6 votes |
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) { boolean z = (typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof InstanceCreator) || (typeAdapter instanceof TypeAdapter); C$Gson$Preconditions.checkArgument(z); if (Primitives.isPrimitive(type) || Primitives.isWrapperType(type)) { throw new IllegalArgumentException("Cannot register type adapters for " + type); } if (typeAdapter instanceof InstanceCreator) { this.instanceCreators.put(type, (InstanceCreator) typeAdapter); } if ((typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer)) { this.factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(TypeToken.get(type), typeAdapter)); } if (typeAdapter instanceof TypeAdapter) { this.factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter) typeAdapter)); } return this; }
Example 2
Source File: FieldAttributeModel.java From che with Eclipse Public License 2.0 | 5 votes |
/** * Build a new field model based on the name and Java type * * @param fieldName the name of the field * @param type the Java raw type that will allow further analyzes * @param declarationClass */ public FieldAttributeModel(String fieldName, Type type, Class declarationClass) { this.fieldName = fieldName; this.type = type; this.typeName = convertType(type); this.dtsType = convertTypeForDTS(declarationClass, type); this.declarationClass = declarationClass; if (typeName.startsWith("Array<") || typeName.startsWith("Map<")) { this.needInitialize = true; } if (this.type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) this.type; Type rawType = parameterizedType.getRawType(); analyzeParametrizedType(parameterizedType, rawType); } else if (Primitives.isPrimitive(this.type) || Primitives.isWrapperType(this.type) || String.class.equals(this.type)) { this.isPrimitive = true; } else if (this.type instanceof Class && ((Class) this.type).isAnnotationPresent(DTO.class)) { this.isDto = true; dtoImpl = this.type.getTypeName() + "Impl"; } else if (this.type instanceof Class && ((Class) this.type).isEnum()) { this.isEnum = true; } }
Example 3
Source File: StorageEntityUtil.java From attic-aurora with Apache License 2.0 | 5 votes |
private static void validateField( String name, Object object, Field field, Set<Field> ignoredFields) { try { field.setAccessible(true); String fullName = name + "." + field.getName(); Object fieldValue = field.get(object); boolean mustBeSet = !ignoredFields.contains(field); if (mustBeSet) { assertNotNull(fullName + " is null", fieldValue); } if (fieldValue != null) { if (Primitives.isWrapperType(fieldValue.getClass())) { // Special-case the mutable hash code field. if (mustBeSet && !fullName.endsWith("cachedHashCode")) { assertNotEquals( "Primitive value must not be default: " + fullName, Defaults.defaultValue(Primitives.unwrap(fieldValue.getClass())), fieldValue); } } else { assertFullyPopulated(fullName, fieldValue, ignoredFields); } } } catch (IllegalAccessException e) { throw Throwables.propagate(e); } }