spring-mvcspring-data-jpajackson2

Where to put JsonIgnore in spring boot


Which is an ideal place to use JsonView or JsonIgnore? DTO or Entity layer? I have added it into the DTO layer but my ignored property is set to Null. and if I don't use I am stuck with infinite recursion


Solution

  • the correct one is for you to use it in the class you are returning, if you are returning the DTO, you must treat it, so that it does not return recursive data, you may need to remodel the class, as it is not very interesting to have infinitely recursive data.

    if you still have doubts about what to do, if possible insert your code so that we can analyze it better.