Example usage for org.springframework.restdocs.payload JsonFieldType VARIES

List of usage examples for org.springframework.restdocs.payload JsonFieldType VARIES

Introduction

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

Prototype

JsonFieldType VARIES

To view the source code for org.springframework.restdocs.payload JsonFieldType VARIES.

Click Source Link

Document

A variety of different types.

Usage

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

@Test
public void multipleFieldsWithDifferentTypes() throws IOException {
    assertThat(this.fieldTypeResolver.resolveFieldType("a[].id",
            createPayload("{\"a\":[{\"id\":1},{\"id\":true}]}")), equalTo(JsonFieldType.VARIES));
}

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 ww w.java2s.  com*/
    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();
    }
}