Example usage for org.springframework.restdocs.payload FieldTypesDoNotMatchException FieldTypesDoNotMatchException

List of usage examples for org.springframework.restdocs.payload FieldTypesDoNotMatchException FieldTypesDoNotMatchException

Introduction

In this page you can find the example usage for org.springframework.restdocs.payload FieldTypesDoNotMatchException FieldTypesDoNotMatchException.

Prototype

FieldTypesDoNotMatchException(FieldDescriptor fieldDescriptor, Object actualType) 

Source Link

Document

Creates a new FieldTypesDoNotMatchException for the field described by the given fieldDescriptor that has the given actualType .

Usage

From source file:org.springframework.restdocs.payload.JsonContentHandler.java

@Override
public Object determineFieldType(FieldDescriptor fieldDescriptor) {
    if (fieldDescriptor.getType() == null) {
        return this.fieldTypeResolver.resolveFieldType(fieldDescriptor.getPath(), readContent());
    }//from   w  w  w. j  ava 2  s  . c  o m
    if (!(fieldDescriptor.getType() instanceof JsonFieldType)) {
        return fieldDescriptor.getType();
    }
    JsonFieldType descriptorFieldType = (JsonFieldType) fieldDescriptor.getType();
    try {
        JsonFieldType actualFieldType = this.fieldTypeResolver.resolveFieldType(fieldDescriptor.getPath(),
                readContent());
        if (descriptorFieldType == JsonFieldType.VARIES || descriptorFieldType == actualFieldType) {
            return descriptorFieldType;
        }
        throw new FieldTypesDoNotMatchException(fieldDescriptor, actualFieldType);
    } catch (FieldDoesNotExistException ex) {
        return fieldDescriptor.getType();
    }
}