Spring Boot Validate Incoming Json With Json Schema

Поділитися
Вставка
  • Опубліковано 15 гру 2024

КОМЕНТАРІ • 21

  • @benstrydom5292
    @benstrydom5292 3 роки тому +2

    Great video! Please explain how to validate json payload using annotations.

    • @MikesTechCorner
      @MikesTechCorner  3 роки тому +1

      You could just try to convert to the type. I would recommend that you always have a schema to validate against. Jackson has a module to create a JSON schema from annotations on classes.

  • @nerfedzst
    @nerfedzst Рік тому +1

    Thanks Mike!! Great job...

    • @MikesTechCorner
      @MikesTechCorner  Рік тому

      Thank you very much for watching and commenting. :-)

  • @prakashkoppal2614
    @prakashkoppal2614 3 роки тому +2

    Thank you so much for this video Sir

  • @debendradey8797
    @debendradey8797 6 місяців тому +1

    Nice one, really I love it ..... :)

  • @madhavareddy8815
    @madhavareddy8815 3 роки тому +2

    Thank you very much. Its very much informative.

    • @MikesTechCorner
      @MikesTechCorner  3 роки тому

      Thx for watching :)

    • @madhavareddy8815
      @madhavareddy8815 3 роки тому

      @@MikesTechCorner Hi Mike,
      1) Is there any way to get custom error messages?
      2) Will it support multilingual?

  • @shomer2009
    @shomer2009 3 роки тому +1

    Thanks, very good tutorial

  • @Imjamalvali
    @Imjamalvali Рік тому

    Hi Mike,
    I have observed one issue with this code.
    I am taking one model class(dto) as my controller class request(using @RequestBody Some ClassName request)
    and calling the jsonvalidator service.
    after calling the jsonvalidator service i am converting my incoming request to string using the ObjectMapper writeValueAsString method.
    after that i have added all the logic which you have written but its failing to validate my json under the rules i have provided in schema.
    Its not validating the type of data and its format.
    Pls help me on this.
    pls let me know if any details required for the above explanation.

    • @MikesTechCorner
      @MikesTechCorner  Рік тому

      Read the Jackson documentation. You need some annotations on your model. And maybe you need 2 models. One for serializing and one for deserializing. It depends on the usecase.

  • @iliabakanidze4779
    @iliabakanidze4779 3 роки тому +1

    Thanks, Mike for a great tutorial. Can we validate (using this library) the JSON which contains a list of objects and get the positions for invalid ones?

    • @MikesTechCorner
      @MikesTechCorner  3 роки тому +1

      I'm not sure how detailed the error message is, but you will get a description of what was wrong with the json.

  • @padmajanvenugopal6839
    @padmajanvenugopal6839 3 роки тому +1

    Hi Mike,
    Just wanted to know how this is different from the default validation provided by spring boot. I mean we can use @NotNull or such annotation by default in spring boot beans. Is there any additional functionality json schema brings in?

    • @MikesTechCorner
      @MikesTechCorner  3 роки тому

      With the default spring validation you just get an exception if the data don't match. Here you can apply extra rules like name should be between 10 and 200 characters.

    • @greyshark9774
      @greyshark9774 Рік тому

      ​@@MikesTechCornerin sprint boot validation you can do this as well

  • @svalyavasvalyava9867
    @svalyavasvalyava9867 2 роки тому

    awesome tutorial, thank you!!!