Skip to content

Spring formatters applied by to all numeric types [SPR-6490] #11156

@spring-projects-issues

Description

@spring-projects-issues

Stefan Schmidt opened SPR-6490 and commented

Assume there is the following use-case:

A form backing object contains the following field annotated with JSR 303:

@Size(min = 16, max = 16)
private Long creditCardNumber;

and this field is bound through Spring MVC:

<form:input path="creditCardNumber" />
<form:errors path="creditCardNumber"/>

The user enters a 15 digit number: 123456789012345 Spring MVC would convert and bind the field, validate it and return it to the form for correction. Only now the field is presented after a default formatting has been applied: 123,456,789,012,345. The user does now need to remove the default formatting to make the Long type valid again.

I think by default formatters for numeric types should be disabled to prevent such unexpected behaviour. Unless the user explicitly asks to format a value (using @NumberFormat(style=Style.CURRENCY)) it should not be applied.


Affects: 3.0 RC3

Referenced from: commits 73a7522

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions