Length validation in example doesn't work
See original GitHub issueI created the simple example app based on the Getting Started guide, and I run into a problem. The Saying
class has the @Length(max = 3)
annotation on its content
property (see here), The guide states
Lastly, the bean leverages validation to ensure the content size is no greater than 3.
This, to my understanding, should prevent any attempt to assign a string longer than 3 characters to the content
property.
However, this does not seem to work. For example, when running curl localhost:8080/hello-world
, the content
will be "Hello, Stranger!"
which is clearly longer than 3 characters.
Please let me know if I’m misunderstanding something.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Is there a minlength validation attribute in HTML5?
Use the minlength(/ maxlength) attribute. It specifies the minimum number of characters. For example, <input type="text" minlength ...
Read more >Keats/validator: Simple validation for Rust structs - GitHub
Tests whether a container does not contain the substring given if it's a string or if a key is NOT present in a...
Read more >validate.js
Validate.js provides a declarative way of validating javascript objects. It is unit tested with 100% code coverage and can be considered fit for...
Read more >Sitecore Forms string length validator not working for other ...
I am using a Sitecore Forms string length validator ...
Read more >How to fix: Attribute “minlength” is only allowed when the input ...
The minlength attribute can be used on an input element to define a client-side validation for the maximum length allowed on an input...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m inclined to agree with you that the example given in the Getting Started guide is somewhat nonsensical; type “Saying” is only used as a return value type from a resource method, whereas most validation situations are more concerned with validating user input, e.g. validating a POSTed bean or validating URL query parameters.
That said, adding the annotation to the resource method as “public @Valid Saying sayHello” could be used to show a more unusual usage to generate HTTP 5xx errors, where the server found the user’s request acceptable but was unable to generate a valid response.
Fixed in #3082.