Serializing fields in a custom exception in Java

Let's say I have a custom RuntimeExceptionone where MyEntityis JPA @Entity:

@Getter
public class MyEntityAlreadyExistingException extends RuntimeException {

    private final MyEntity myEntity;

    public MyEntityAlreadyExistingException(MyEntity myEntity) {
        super(MessageFormat.format("MyEntity with name \"{0}\" already exists", myEntity.getName()));
        this.myEntity = myEntity;
    }
}

Sonar is hinting to make it MyEntitytransitional or serializable.

How can I solve this situation?

I do not use any RMI, deleting everything. It is a relatively simple Spring boot web application with JPA in place.

What benefits can I use later if I made serializable MyEntity?

+4
source share
1 answer

How can I solve this situation?

, - RMI, ( Sonar ) - .

, - . , Serializable, - .

P.S. Sonar .

+1

Source: https://habr.com/ru/post/1692624/


All Articles