S
S
Sneiksus2021-12-10 13:16:26
Java
Sneiksus, 2021-12-10 13:16:26

How to save a complex object in java?

There is a class that contains a list of other objects, which can also contain an object. What is the easiest way to store such a class in a file?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Orkhan, 2021-12-10
@Sneiksus

Good evening.
You can solve your problem in different ways.
For example serialize your object/s to json/xml/yaml. As noted by colleague Dmitry Roo , see either jackson, gson. If we are talking about android, then there are others too.
Well, or for example, you can use protobuf
https://developers.google.com/protocol-buffers
Useful links:
https://www.baeldung.com/java-serialization-approaches
https://www.baeldung.com/java -serialization

S
Sergey Gornostaev, 2021-12-10
@sergey-gornostaev

Any serializer will do the job, as long as the objects are serializable.

D
Dmitry Roo, 2021-12-10
@xez

I would save as json (see gson, jackson)

V
Vladimir Korotenko, 2021-12-10
@firedragon

serialization.
only the following conditions must be met.
The data must be self-sufficient,
some resources must be restored during deserialization. (e.g. database connection)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question