ru.tinkoff.kora.http.server.common.StringParameterReadersModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http-server-common Show documentation
Show all versions of http-server-common Show documentation
Kora http-server-common module
package ru.tinkoff.kora.http.server.common;
import ru.tinkoff.kora.application.graph.TypeRef;
import ru.tinkoff.kora.common.DefaultComponent;
import ru.tinkoff.kora.http.server.common.handler.EnumStringParameterReader;
import ru.tinkoff.kora.http.server.common.handler.StringParameterReader;
import java.util.UUID;
public interface StringParameterReadersModule {
@DefaultComponent
default > StringParameterReader enumStringParameterReader(TypeRef typeRef) {
return new EnumStringParameterReader<>(typeRef.getRawType().getEnumConstants(), Enum::name);
}
@DefaultComponent
default StringParameterReader javaTimeOffsetTimeStringParameterReader() {
return StringParameterReader.of(java.time.OffsetTime::parse, "Parameter has incorrect value '%s', expected format is '10:15:30+01:00'"::formatted);
}
@DefaultComponent
default StringParameterReader javaTimeOffsetDateTimeStringParameterReader() {
return StringParameterReader.of(java.time.OffsetDateTime::parse, "Parameter has incorrect value '%s'', expected format is '2007-12-03T10:15:30+01:00'"::formatted);
}
@DefaultComponent
default StringParameterReader javaTimeLocalTimeStringParameterReader() {
return StringParameterReader.of(java.time.LocalTime::parse, "Parameter has incorrect value '%s'', expected format is '10:15'"::formatted);
}
@DefaultComponent
default StringParameterReader javaTimeLocalDateTimeStringParameterReader() {
return StringParameterReader.of(java.time.LocalDateTime::parse, "Parameter has incorrect value '%s'', expected format is '2007-12-03T10:15:30'"::formatted);
}
@DefaultComponent
default StringParameterReader javaTimeLocalDateStringParameterReader() {
return StringParameterReader.of(java.time.LocalDate::parse, "Parameter has incorrect value '%s'', expected format is '2007-12-03'"::formatted);
}
@DefaultComponent
default StringParameterReader javaTimeZonedDateTimeStringParameterReader() {
return StringParameterReader.of(java.time.ZonedDateTime::parse, "Parameter has incorrect value '%s'', expected format is '2007-12-03T10:15:30+01:00[Europe/Paris]'"::formatted);
}
@DefaultComponent
default StringParameterReader javaUtilIntegerStringParameterReader() {
return StringParameterReader.of(Integer::parseInt, "Parameter has incorrect value '%s' for 'Integer' type"::formatted);
}
@DefaultComponent
default StringParameterReader javaUtilDoubleStringParameterReader() {
return StringParameterReader.of(Double::parseDouble, "Parameter has incorrect value '%s' for 'Double' type"::formatted);
}
@DefaultComponent
default StringParameterReader javaUtilLongStringParameterReader() {
return StringParameterReader.of(Long::parseLong, "Parameter has incorrect value '%s' for 'Long' type"::formatted);
}
@DefaultComponent
default StringParameterReader javaUtilFloatStringParameterReader() {
return StringParameterReader.of(Float::parseFloat, "Parameter has incorrect value '%s' for 'Float' type"::formatted);
}
@DefaultComponent
default StringParameterReader javaUtilUUIDStringParameterReader() {
return StringParameterReader.of(UUID::fromString, "Parameter has incorrect value '%s' for 'UUID' type"::formatted);
}
@DefaultComponent
default StringParameterReader javaUtilBooleanStringParameterReader() {
return StringParameterReader.of(Boolean::parseBoolean, "Parameter has incorrect value '%s' for 'Boolean' type"::formatted);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy