io.hyperfoil.core.parser.ReflectionParser Maven / Gradle / Ivy
package io.hyperfoil.core.parser;
import java.util.function.Function;
import org.yaml.snakeyaml.events.Event;
import org.yaml.snakeyaml.events.MappingEndEvent;
import org.yaml.snakeyaml.events.MappingStartEvent;
import org.yaml.snakeyaml.events.ScalarEvent;
class ReflectionParser extends BaseReflectionParser implements Parser {
private final Function selector;
ReflectionParser(Function selector) {
this.selector = selector;
}
@Override
public void parse(Context ctx, T target) throws ParserException {
S builder = selector.apply(target);
ctx.expectEvent(MappingStartEvent.class);
while (ctx.hasNext()) {
Event next = ctx.next();
if (next instanceof MappingEndEvent) {
return;
} else if (next instanceof ScalarEvent) {
invokeWithParameters(ctx, builder, (ScalarEvent) next);
} else {
throw ctx.unexpectedEvent(next);
}
}
throw ctx.noMoreEvents(MappingEndEvent.class);
}
}