Java toString puts json (gson impl) on logs

Viewed 2081

I have multiple classes with toString: some of these have collections.

Is this a good idea to create toString with gson?

@Override
public String toString() {
    return new Gson().toJson(this);
}

I use toString for logging with log4j. I don't want exceptions on toString output. Anyone use this implementation?

Maybe it's a duplicate question, but I don't find the right answer

2 Answers
Related