com.neotys.neoload.model.v3.binding.serializer.UserPathSerializer Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.binding.serializer;
import static com.neotys.neoload.model.v3.project.Element.DESCRIPTION;
import static com.neotys.neoload.model.v3.project.Element.NAME;
import static com.neotys.neoload.model.v3.project.userpath.UserPath.ACTIONS;
import static com.neotys.neoload.model.v3.project.userpath.UserPath.DEFAULT_USER_SESSION;
import static com.neotys.neoload.model.v3.project.userpath.UserPath.END;
import static com.neotys.neoload.model.v3.project.userpath.UserPath.INIT;
import static com.neotys.neoload.model.v3.project.userpath.UserPath.USER_SESSION;
import static com.neotys.neoload.model.v3.project.userpath.assertion.AssertionsElement.ASSERTIONS;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.neotys.neoload.model.v3.project.userpath.Container;
import com.neotys.neoload.model.v3.project.userpath.UserPath;
import com.neotys.neoload.model.v3.project.userpath.assertion.Assertion;
public final class UserPathSerializer extends StdSerializer {
private static final long serialVersionUID = -9059965357953456780L;
public UserPathSerializer() {
super(UserPath.class);
}
@Override
public void serialize(final UserPath userPath, final JsonGenerator generator, final SerializerProvider provider) throws IOException {
generator.writeStartObject();
generator.writeStringField(NAME, userPath.getName());
final Optional description = userPath.getDescription();
if (description.isPresent()) {
generator.writeStringField(DESCRIPTION, description.get());
}
final UserPath.UserSession userSession = userPath.getUserSession();
if (userSession != DEFAULT_USER_SESSION) {
generator.writeObjectField(USER_SESSION, userSession);
}
final Optional init = userPath.getInit();
if (init.isPresent()) {
generator.writeObjectField(INIT, Container.builder().from(init.get()).name("").build());
}
final Container actions = userPath.getActions();
if (actions != null) {
generator.writeObjectField(ACTIONS, Container.builder().from(actions).name("").build());
}
final Optional end = userPath.getEnd();
if (end.isPresent()) {
generator.writeObjectField(END, Container.builder().from(end.get()).name("").build());
}
final List assertions = userPath.getAssertions();
if ((assertions != null) && (!assertions.isEmpty())) {
AssertionsSerializer.serialize(generator, ASSERTIONS, assertions);
}
generator.writeEndObject();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy