I've been using the @JsonIgnore because when I get a list of all users, there is a foreign key of company to match the company of the user, and when I do a get request, without @JsonIgnore, it creates an infinite loop that crashes the program.
However, when doing a post request, I cannot post the company to the user with the @JsonIgnore in there, because it comes up null.
Assuming that a Company that the User will be a member of already exists, wouldn't you just want to provide an identifier for the Company, and not all of the company's attributes when creating a new User?
Also, why does Company have a collection of the Users? That is going to create a kind of circular reference which is probably the source of your infinite loop.
Web service layer:
The User class from the business layer has no idea about the web service layer or the persistence layer. It is the primary class that models a user, and if you want to perform logic on a user, you will want to do it with this class. It may contain circular references: A User references a Company and the referenced Company may refer back to the User.
The UserEntity class from the persistence layer is very similar to the User class from the business layer. The main reason it's separate is because it's not easy to enforce class invariants on JPA entities. Therefore you only use it when you want to persist your user to the database, or when you want to retrieve it from the database. Immediately convert it to a User object, and don't perform logic on it directly.
The UserData class from the web service layer is a flattened object model that you can use to (de)serialize requests and responses to the web service. There are two major differences with the other two classes: First, it doesn't contain a reference to a company instance, because you should not have circular references in your requests and responses. Secondly, it doesn't contain an ID that was generated by the DBMS. You must not expose such IDs to the outside world.
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
SKIP - a book about connecting industrious people with elderly land owners