question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Length validation in example doesn't work

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
skradelcommented, Dec 7, 2019

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.

0reactions
acsbendicommented, Jan 5, 2020

Fixed in #3082.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found