title: How to write custom type validator for Spring REST Docs?
body: <p>In Spring REST Docs, I can document fields of a JSON response. Additionally, I can specify the type where I can either pass a <code>JsonFieldType</code>, e.g. <code>JsonFieldType.STRIGN</code>. This will actually be validated, meaning the test will fail when e.g. a number is returned instead.</p>
  
  <pre><code>(...)
      .andDo( document( "one-valid-connection",
            pathParameters( parameterWithName( "ip" ).description( "The requested IPv4 address." ) ),
            responseFields( 
                  fieldWithPath( "username" ).type( JsonFieldType.STRING ).description( "The name of the user that initiated the connection." ),
                  fieldWithPath( "ipAddress" ).type( JsonFieldType.STRING ).description( "The IPv4 address of the user." ),
                  fieldWithPath( "startTime" ).type( JsonFieldType.STRING ).description( "The time (ISO 8601 format) when the connection has been initiated." ),
                  fieldWithPath( "stopTime" ).type( JsonFieldType.STRING ).description( "The time (ISO 8601 format) when the connection has been terminated or `null` if connection is still active." )
             )
      ) );
  </code></pre>
  
  <p>My question is, is it possible to write custom types to support e.g. IP addresses, ISO timestamps, Enums and maybe even valid numeric ranges <em>and</em> to support custom validation (e.g. regex or more complex logic)?</p>
  
  <p>As pseudo code, something like</p>
  
  <pre><code>          responseFields( 
                  fieldWithPath( "username" ).type( JsonFieldType.STRING )
                  fieldWithPath( "ipAddress" ).type( CustomTypes.IPV4_ADDRESS ),
                  fieldWithPath( "startTime" ).type( CustomTypes.ISO8601_TIMESTAMP ),
                  fieldWithPath( "stopTime" ).type( CustomTypes.ISO8601_TIMESTAMP ),
                  fieldWithPath( "type" ).type( CustomTypes.CONNECTION_ENUM ),
                  fieldWithPath( "duration" ).type( CustomTypes.createIntRange(0,999999) )
             )
  </code></pre>