I have a list of persons in DB everyone having a CV field which is a MultiPart File in Spring. I’m trying to get all persons from db, but to ignore the CV field because I don’t want to be downloaded when I use getAllPerson function. It is possible?
Advertisement
Answer
If you only want to ignore a field when serializing to JSON you could use @JsonIgnore
tag.
If you want to inlcude it on the Json but not on the Jpa use @Transient
and @JsonInclude
tags.
If you just want to not read and specific field from the database every time you get an element then you could use Lazy loading on that field. Then, only when you use the getters for that field you will retrieve it from the DB.
Finally, if you want different serializations on JSON you can use JSON Views. This will allow you to define diferent views of the same object and select the one you want to use when serializing.
All this tools can be used in concordance to achieve whatever you want.