Java toString puts json (gson impl) on logs Java toString puts json (gson impl) on logs json json

Java toString puts json (gson impl) on logs


You may want to consider Apache Common's Reflection toString Builder. It should be faster than Gson, but still not need to be modified when you add new fields to the model.

@Overridepublic String toString() {     return ReflectionToStringBuilder.toString(this);}


Gson output may be "large" on collections with complex objects.

After evaluate some scenarios, I prefer to use Gson only in specific points.

log.info("[context scenario] Collection<Foo>" + new Gson().toJson(foos));