com.worldturner.medeia.parser.jackson.JacksonValidatingStreamCopier.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of medeia-validator-jackson Show documentation
Show all versions of medeia-validator-jackson Show documentation
Medeia streaming JSON-schema validator for the JVM platform,
Jackson module.
The newest version!
package com.worldturner.medeia.parser.jackson
import com.fasterxml.jackson.core.JsonFactory
import com.fasterxml.jackson.core.JsonParser
import com.worldturner.medeia.parser.AbstractValidatingStreamCopier
import com.worldturner.medeia.schema.validation.SchemaValidator
import com.worldturner.medeia.schema.validation.stream.SchemaValidatingConsumer
import java.io.InputStream
import java.io.OutputStream
class JacksonValidatingStreamCopier(
source: InputStream,
target: OutputStream,
validator: SchemaValidator,
inputSourceName: String?,
private val jsonFactory: JsonFactory
) : AbstractValidatingStreamCopier(source, target, validator, inputSourceName) {
private val parser = createParser()
private fun createParser(): JsonParser {
val jsonParser = jsonFactory.createParser(ValidatorInputStream())
val consumer = SchemaValidatingConsumer(validator)
return JacksonTokenDataJsonParser(
consumer = consumer,
jsonParser = jsonParser,
inputSourceName = inputSourceName
)
}
fun copy() {
while (parser.nextToken() != null) {
}
}
}