Package org.instancio.generator.specs
Interface AsGeneratorSpec<T>
- Type Parameters:
T- generated type
- All Superinterfaces:
GeneratorSpec<T>
- All Known Subinterfaces:
BigDecimalGeneratorSpec,BigDecimalSpec,BigIntegerSpec,BooleanGeneratorSpec,BooleanSpec,ByteSpec,CharacterGeneratorSpec,CharacterSpec,DoubleSpec,EmailGeneratorSpec,EmailSpec,EnumGeneratorSpec<E>,EnumSpec<E>,FilePathSpec<T>,FileSpec,FloatSpec,HashGeneratorSpec,HashSpec,InstantGeneratorSpec,InstantSpec,IntegerSpec,LocalDateSpec,LocalDateTimeGeneratorSpec,LocalDateTimeSpec,LocalTimeGeneratorSpec,LocalTimeSpec,LongSpec,LuhnGeneratorSpec,LuhnSpec,Mod10GeneratorSpec,Mod10Spec,Mod11GeneratorSpec,Mod11Spec,MonthDayGeneratorSpec,MonthDaySpec,NumberGeneratorSpec<T>,NumberSpec<T>,NumericSequenceGeneratorSpec<T>,NumericSequenceSpec<T>,OffsetDateTimeGeneratorSpec,OffsetDateTimeSpec,OffsetTimeGeneratorSpec,OffsetTimeSpec,PathGeneratorSpec<T>,PathSpec,ShortSpec,SinGeneratorSpec,SinSpec,TemporalGeneratorSpec<T>,TemporalSpec<T>,TextPatternGeneratorSpec,TextPatternSpec,URIGeneratorSpec,URISpec,URLGeneratorSpec,URLSpec,YearMonthSpec,YearSpec,ZonedDateTimeGeneratorSpec,ZonedDateTimeSpec
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 LogEntry(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
-