1
[
    {
    "id" : "Unique_Id25",
    "firstName" : "Test Name",
    "firstName" : "Test Name 2",
    }
]

Above I have an example of a duplicate key, firstName. I use Postman and it warns that a duplicate key exists, but the POST request passes as I don't currently validate for it.

So I'm asking if there's a cool java/spring way of checking for this duplicate and throwing an exception.

Otherwise I'll try to build these JSON keys into an array and looping through.

CubeJockey
  • 2,209
  • 8
  • 24
  • 31
  • Related: [How do I validate incoming JSON data inside a REST service?](http://stackoverflow.com/questions/18154983/how-do-i-validate-incoming-json-data-inside-a-rest-service) – CubeJockey Jun 15 '16 at 17:14
  • I've been using http://json-schema-validator.herokuapp.com/ to test but no success are validating duplicate key elements. – Darren Broderick DBro Jun 17 '16 at 08:38

1 Answers1

0
@Autowired
ObjectMapper jsonObjectMapper;

Use ObjectMapper to enable duplicate detection

jsonObjectMapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
pradosh nair
  • 913
  • 1
  • 16
  • 28