0

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.

Indrajeet Gour
  • 4,020
  • 5
  • 43
  • 70
  • You have an existing JSON data in DB and want to add something in it and then want to save it as JSON, is it? – Romil Patel Jul 31 '19 at 06:36
  • No DB has row level data only which I mapped with Entity class, I just wanted to add another attribute for destination as Spring GET method by default return JSON only, that is why I mentioned that to add additional attribute into JSON. – Indrajeet Gour Jul 31 '19 at 06:43

2 Answers2

3

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.

YoManTaMero
  • 391
  • 4
  • 10
1

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