Package io.vertx.openapi.validation.analyser

## Class ContentAnalyser

- java.lang.Object
- - io.vertx.openapi.validation.analyser.ContentAnalyser

- Direct Known Subclasses:
    `ApplicationJsonAnalyser`, `MultipartFormAnalyser`

      public abstract class ContentAnalyser
      extends Object

  The content analyser is responsible for checking if the content is syntactically correct, and transforming the content.

  These two methods are intentionally bundled in `ContentAnalyser` to prevent some operations from having to be performed twice. This is particularly helpful if a library is used that cannot distinguish between these steps. In this case, an intermediate result that was generated in `checkSyntacticalCorrectness()`, for example, can be reused.

  Therefore, it is very important to ensure that the `checkSyntacticalCorrectness()` method is always called before.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected Buffer` | `content` |
    `protected String` | `contentType` |
    `protected ValidationContext` | `requestOrResponse` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ContentAnalyser​(String contentType, Buffer content, ValidationContext context)` | Creates a new content analyser.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected static ValidatorException` | `buildSyntaxException​(String message)` | Builds a `ValidatorException` for the case that the content is syntactically incorrect.
    `abstract void` | `checkSyntacticalCorrectness()` | Checks if the content is syntactically correct.
    `protected static Object` | `decodeJsonContent​(Buffer content, ValidationContext requestOrResponse)` | Decodes the passed content as JSON.
    `static ContentAnalyser` | `getContentAnalyser​(MediaType mediaType, String contentType, Buffer content, ValidationContext context)` | Returns the content analyser for the given content type.
    `abstract Object` | `transform()` | Transforms the content into a format that can be validated by the `RequestValidator`, or `ResponseValidator`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### contentType

          protected final String contentType

    - #### content

          protected final Buffer content

    - #### requestOrResponse

          protected final ValidationContext requestOrResponse

  - ### Constructor Detail

    - #### ContentAnalyser

          public ContentAnalyser​(String contentType,
                                 Buffer content,
                                 ValidationContext context)

      Creates a new content analyser.
      Parameters:
        `contentType` - the content type.
        `content` - the content to be analysed.
        `context` - the context in which the content is used.

  - ### Method Detail

    - #### getContentAnalyser

          public static ContentAnalyser getContentAnalyser​(MediaType mediaType,
                                                           String contentType,
                                                           Buffer content,
                                                           ValidationContext context)

      Returns the content analyser for the given content type.
      Parameters:
        `mediaType` - the media type to determine the content analyser.
        `contentType` - the raw content type value from the HTTP header field.
        `content` - the content to be analysed.
      Returns:
        the content analyser for the given content type.

    - #### checkSyntacticalCorrectness

          public abstract void checkSyntacticalCorrectness()

      Checks if the content is syntactically correct.

      Throws a `ValidatorException` if the content is syntactically incorrect.

    - #### transform

          public abstract Object transform()

      Transforms the content into a format that can be validated by the `RequestValidator`, or `ResponseValidator`.

      Throws a `ValidatorException` if the content can't be transformed.

      Returns:
        the transformed content.

    - #### buildSyntaxException

          protected static ValidatorException buildSyntaxException​(String message)

      Builds a `ValidatorException` for the case that the content is syntactically incorrect.
      Parameters:
        `message` - the error message.
      Returns:
        the `ValidatorException`.

    - #### decodeJsonContent

          protected static Object decodeJsonContent​(Buffer content,
                                                    ValidationContext requestOrResponse)

      Decodes the passed content as JSON.
      Returns:
        an object representing the passed JSON content.
      Throws:
        `ValidatorException` - if the content can't be decoded.