Home > Back-end >  JPA/Hibernate Entity show only some fields on GET
JPA/Hibernate Entity show only some fields on GET

Time:02-03

I have an entity that has many fields mapped to columns in my database using the @Entity and @Column annotations. Columns might include something like timestamps and user IDS. Is there any built-in way to exclude certain variables from being shown/parsed into JSONon GET after querying for my entity? For example, don’t show the user ID column, only the time stamp? I still need the fields in my entity for my POST methods so that I can insert or update the entities.

CodePudding user response:

It is nothing to do with the Hibernate/JPA but depending on which JSON framework that you use to serialise the entity to JSON. so you should checkout the documentation of the JSON framework that you use.

In case you are using , you can simply use @JsonIgnore to annotate the field that you want to exclude in JSON such as :

@Entity
@Table("foo")
public class FooEntity {
   
   @Id
   @JsonIgnore
   private Long id;
}
  •  Tags:  
  • Related