Indrajeet Gour
Indrajeet Gour

Reputation: 4490

Adding Dynamic attribute on Spring Boot application

I have one spring boot application where I am fetching the data from my database table its one way not updating, for that I created one Entity class.

Now case if like that, where I wanted to added few more attributes into existing Entity[It is the JSON at the end], finally I am pushing the update JSON entity into destination system.

I just wanted to add more extra attributes which destination host wanted, and it is not coming from source table.

Upvotes: 0

Views: 1582

Answers (2)

YoManTaMero
YoManTaMero

Reputation: 391

If you mean additional column in Entity class that you don't want to save into database, use @Transient.

@Transient
private String destination;

You can set the values but will only be transient and will not be from database.

If you want to add/merge another json check this.

Upvotes: 3

May be could be usefull for you add a new transient attribute on your entity that contains the json attributes (a custom object or the json value as String) Then create a new field on database to store the value.

If this attribute is a String it's all done but if not, if were a custom object, you should use the jpa annotations below to do the conversion object/json and json/object when create/update on database and load from database:

@PrePersist, @PreUpdate, @PostLoad

Upvotes: 1

Related Questions