1

I have the following annotation in an entity:

private Map<@Size(max = 10) String, Chart> charts = new HashMap<>();

When I try to put an object with a long key to the map then I got the following validation error:

{
  "errors": [
    {
      "entity": "Report",
      "property": "charts[ffdsfdfdsdsffdsfds]",
      "invalidValue": {
        "id": 2,
        "name": "visitors",
        ... additional properties ...
      },
      "message": "length must be between 0 and 10",
      "code": "Size"
    }
  ],
}

My problem is that it returns the value of the map-entry as an invalidValue, instead of the key of the entry (which is actually validated).

(This object is really big, with additional lists and maps in it, and all of them are rendered into the error message.)

So, how can I make the validator engine to add

"invalidValue": "ffdsfdfdsdsffdsfds"

into the message? (Or - if it's not possible - how can I turn off adding the invalidValue property to the message - but only at this one particular place?)

Selindek
  • 3,269
  • 1
  • 18
  • 25
  • I think, You have to write a "custom validator" ([link](https://stackoverflow.com/a/781486/592355)), since not the String (key) is invalid, but the "whole entry"(key+value)... – xerx593 Jan 18 '19 at 20:08
  • 1
    I created a unique constraint-validator. The validator-api allows to sign the key of an entry as the target object. (They even have a special constant for it: '') But even if I explicitly set it I still get the same 'property' and 'invalidValue' result. So I start to believe that there is bug in the validation-api. – Selindek Jan 19 '19 at 20:20

0 Answers0