Skip to content

Passing Objects as parameters #52

@adefran83

Description

@adefran83

When passing an object as a parameter to a cloud endpoint, it passes it as a payload and the app engine can't interpret it. However if you send each item of the object separately it works just fine.

Example:
The endpoint method

@ApiMethod(name = "setFavorite", httpMethod = "post")
    public void setFavorite(Photo photo, @Named("user") String user) throws IOException {
        log.log(Level.WARNING, photo.toString());
        photo.setOwner(user);
        Entity photoEntity = new Entity("Photo");
        photoEntity.setProperty("photoId", photo.getPhotoId());
        photoEntity.setProperty("ownerId", photo.getOwner());
        photoEntity.setProperty("photoName", photo.getPhotoName());
        photoEntity.setProperty("albumName", photo.getAlbumName());
        photoEntity.setProperty("photoThumbnail", photo.getPhotoThumbnail());
        photoEntity.setProperty("isFavorite", true);
        photoEntity.setProperty("photoUrl", photo.getPhotoUrl());
        datastore.put(photoEntity);
    }

The photo object:

 public String photoName;
    public String photoUrl;
    public String albumName;
    public int photoNumber;
    public String photoThumbnail;
    public boolean isFavorite;
    public String ownerId;
    public String photoId;
    public Key photoKey;

The code that only sends the user and sends the photo object as a payload(which doesnt work):

var photoApi = document.getElementById('photoApi');
var request = photoApi.api.setFavorite({
  user: gapi.auth2.getAuthInstance().currentUser.get().getId(),
  photo: _photo
});

The code that works:

var photoApi = document.getElementById('photoApi');
var request = photoApi.api.setFavorite({
  user: gapi.auth2.getAuthInstance().currentUser.get().getId(),
  photoName: _photo.photoName,
  photoId: _photo.photoId,
  albumName: _photo.albumName,
  photoThumbnail: _photo.photoThumbnail,
  isFavorite: true,
  photoUrl: _photo.photoUrl
});

Is this expected behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions