1

My model is like:

public class MyModel{
    private String mId;
    private String mName;
    T mAnObject;
}

How can I store T object in database.

Charu
  • 1,055
  • 13
  • 18

3 Answers3

0

If you need to save specific properties, just do that, otherwise you could serialize it to JSON, as an option (as demonstrated here).

Community
  • 1
  • 1
Ricky
  • 7,785
  • 2
  • 34
  • 46
0

Example: Object myObj has three properties: String title, String subtitle, String text

1 - You can save them as separate database rows and then when you read from the database you recombine them to create your Object.

2 - You can also use Json to save the properties, this way you only need to store a single String in the database and when you read from the database convert the Json String to your Object.

MattButtMatt
  • 461
  • 2
  • 11
  • 26
0

You can save it with JsonNode class

Bilol
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 20 '23 at 23:42