If you just want to replace the line breaks with the following, then you can. Improve it, the return value of toStringMethod should use replaceAll instead of replace. If you want every POJO's toString to call toStringMethod, unfortunately it's not possible because POJO.toString calls toStringMethod, and you also see that toStringMethod calls POJO.toString, causing stack overflow due to cyclic method dependencies. Generally speaking, toString can be automatically generated using IDEA or annotated using LomBok's @ AKS class