Package org.instancio.generator.specs
Interface AsGeneratorSpec<T>
- Type Parameters:
T- generated type
- All Superinterfaces:
GeneratorSpec<T>
- All Known Subinterfaces:
BigDecimalAsGeneratorSpec,BooleanAsGeneratorSpec,CharacterAsGeneratorSpec,EmailAsGeneratorSpec,EnumAsGeneratorSpec<E>,HashAsGeneratorSpec,InstantGeneratorAsSpec,LocalDateTimeGeneratorAsSpec,LocalTimeGeneratorAsSpec,LuhnAsGeneratorSpec,Mod10AsGeneratorSpec,Mod11AsGeneratorSpec,MonthDayGeneratorSpec,NumberAsGeneratorSpec<T>,NumericSequenceAsGeneratorSpec<T>,OffsetDateTimeGeneratorAsSpec,OffsetTimeGeneratorAsSpec,PathAsGeneratorSpec<T>,SinAsGeneratorSpec,TemporalAsGeneratorSpec<T>,TextPatternAsGeneratorSpec,URIAsGeneratorSpec,URLAsGeneratorSpec,ZonedDateTimeGeneratorAsSpec
Allows mapping the result of a generator to another type.
- Since:
- 2.11.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault <R> GeneratorSpec<R> Converts the generated value to another type using the specified mapping function.default GeneratorSpec<String> asString()Converts the generated value to aString.
-
Method Details
-
asString
Converts the generated value to aString.- Returns:
- generator spec with the result mapped to a string
using
Object.toString() - Since:
- 2.11.0
-
as
Converts the generated value to another type using the specified mapping function.Example:
record Log(String msg, long timestamp) {} LogEntry result = Instancio.of(LogEntry.class) .generate(field(Log::timestamp), gen -> gen.temporal().instant().past().as(Instant::toEpochMilli)) .create();- Type Parameters:
R- resulting type after applying the function- Parameters:
mappingFunction- for mapping generated value to another type- Returns:
- generator spec with mapped result
- Since:
- 2.11.0
-