Igor Romanov
Igor Romanov

Reputation: 1717

How to bind form fields to model if property names are different?

I am using Play Framework 2.1

I have POST request coming from external system and trying to bind it to my model, but names of model properties are different from parameter names in request: request has "body-plain" and model has "bodyPlain" etc. How can I indicate mapping from form names to model properties' names?

I'm trying to bind model like this:

Form<MailGunMessageData> mgDataForm = form(MailGunMessageData.class);
MailGunMessageData mgData = mgDataForm.bindFromRequest().get();

Upvotes: 2

Views: 511

Answers (1)

biesior
biesior

Reputation: 55798

You don't need to bind to your everytime, you can also just use DynamicForm and then bind only selected fields from any data:

DynamicForm df = form().bindFromRequest();
MailGunMessageData mgData = new MailGunMessageData();

mgData.mail = df.get("email-address");

Upvotes: 1

Related Questions