M
M
mitaichik2015-05-15 13:22:17
Java
mitaichik, 2015-05-15 13:22:17

Is it possible to use Gson as a singleton?

Hello! In all the examples and codes I have seen, the gson object is created directly at the serialization site.
Can it be used as a singleton? To not create every time?
Maybe there are some problems with multithreading, so it needs to be created in the place of direct use?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bromzh, 2015-05-15
@bromzh

Can. It does not store internal state. Just make the singleton thread-safe.

T
Timur, 2015-05-15
@timych

I always use it as a static class member. Didn't notice any problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question