Skip to content

Revise DataTable transformation #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package aquality.selenium.template.cucumber.transformations;

import aquality.selenium.template.models.ContactUsInfo;
import io.cucumber.java.DataTableType;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.cucumber.java.DefaultDataTableEntryTransformer;

import java.lang.reflect.Type;
import java.util.Map;

public class DataTableTypeTransformations {

@DataTableType
public ContactUsInfo getContactUsInfo(Map<String, String> entry) {
ContactUsInfo contactUsInfoModel = new ContactUsInfo();
contactUsInfoModel.setName(entry.get("Name"));
contactUsInfoModel.setCompany(entry.get("Company"));
contactUsInfoModel.setPhone(entry.get("Phone"));
contactUsInfoModel.setComment(entry.get("Comment"));
return contactUsInfoModel;
private final ObjectMapper mapper = new ObjectMapper();

@DefaultDataTableEntryTransformer
public Object transformDataTable(Map<String, String> entry, Type toValueType) {
JavaType constructedType = mapper.constructType(toValueType);
return mapper.convertValue(entry, constructedType);
}
}