Example usage for com.google.gson.internal Primitives unwrap

List of usage examples for com.google.gson.internal Primitives unwrap

Introduction

In this page you can find the example usage for com.google.gson.internal Primitives unwrap.

Prototype

@SuppressWarnings("unchecked")
public static <T> Class<T> unwrap(Class<T> type) 

Source Link

Document

Returns the corresponding primitive type of type if it is a wrapper type; otherwise returns type itself.

Usage

From source file:org.apache.aurora.scheduler.storage.testing.StorageEntityUtil.java

License:Apache License

private static void validateField(String name, Object object, Field field, Set<Field> ignoredFields) {

    try {/*from   w ww. j a  v a 2 s. c  o  m*/
        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);
    }
}