Skip to content

Let the DataBinder construct nested objects #20806

Closed
@spring-projects-issues

Description

@spring-projects-issues

Hans Desmet opened SPR-16259 and commented

Since Spring 5, the DataBinder can use the parametrized constructor to populate the command object upon form submission, which is a great improvement.

It would be nice and handy if the DataBinder could also use the parametrized constructor on nested objects of the command object.

When using following class for the command object:

public class Line {
	private final Point point1;
	private final Point point2;
	public Line(Point point1, Point point2) {
		this.point1 = point1;
		this.point2 = point2;
	}
	public Point getPoint1() {
		return point1;
	}
	public Point getPoint2() {
		return point2;
	}	
}

which has following class for the nested object:

public class Point {
	private final int x;
	private final int y;
	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}
	public int getX() {
		return x;
	}
	public int getY() {
		return y;
	}
}

upon form submission an Exception occurs:

Invalid property 'point1' of bean class [be.vdab.entities.Line]: Could not instantiate property type [be.vdab.valueobjects.Point] to auto-grow nested property path; nested exception is java.lang.NoSuchMethodException: be.vdab.valueobjects.Point.\<init>()

Affects: 5.0.2

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions