jeudi 19 décembre 2019

Putting model both on client and server

I havent find any proper example so i will ask the following question since i fail to understand how it works without an actual example.

lets say server (backend) has following :

@Entity
public class WebsiteUser {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    private String name;
    private String email; 
  //getters and setters omited for clarity

then something like this

@RepositoryRestResource(collectionResourceRel = "users", path = "users")
public interface UserRepository extends PagingAndSortingRepository<WebsiteUser, Long> {
    List<WebsiteUser> findByName(@Param("name") String name);
}

json

{
  "name" : "test",
  "email" : "test@test.com",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/users/1"
    },
    "websiteUser" : {
      "href" : "http://localhost:8080/users/1"
    }
  }
}

(this is usually much more complicated and has more layers but il try to narrow down the scope of my question)

Now lets say my client is standard java desktop application (swing/javafx) or android , which consumes the json from this link, and i have seen that there are few librarys(gson) that can covert json to model(object).

Now my question is, does the client need to have a copy of model class ? for example client needs to bind UI fields to object fields, and to convert json to model you obviously need to know the model fields. If that is so, it means changing entity fields on server would result in need to change the following field in client also.

Or is there any other way to accomplish this?

if you can give me something to read about this would be good, though a proper example of this client/server problem would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire