All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.javalin.core.validation.BodyValidator.kt Maven / Gradle / Ivy

There is a newer version: 6.2.0
Show newest version
/*
 * Javalin - https://javalin.io
 * Copyright 2017 David Åse
 * Licensed under Apache 2.0: https://github.com/tipsy/javalin/blob/master/LICENSE
 */

package io.javalin.core.validation

import io.javalin.plugin.json.JsonMapper
import org.jetbrains.annotations.NotNull

const val REQUEST_BODY = "REQUEST_BODY"

open class BodyValidator(stringValue: String?, clazz: Class, jsonMapper: JsonMapper) : BaseValidator(stringValue, clazz, REQUEST_BODY, jsonMapper) {
    fun check(check: Check, error: String) = check(REQUEST_BODY, check, error)
    fun check(check: Check, error: ValidationError) = check(REQUEST_BODY, check, error)
    fun check(fieldName: String, check: Check, error: String) = addRule(fieldName, { check(it!!) }, error) as BodyValidator
    fun check(fieldName: String, check: Check, error: ValidationError) = addRule(fieldName, { check(it!!) }, error) as BodyValidator

    @NotNull // there is a null-check in BaseValidator
    override fun get(): T = super.get()!!
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy