Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing Objects as parameters #52

Open
adefran83 opened this issue Aug 1, 2015 · 2 comments
Open

Passing Objects as parameters #52

adefran83 opened this issue Aug 1, 2015 · 2 comments

Comments

@adefran83
Copy link

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?

@ebidel
Copy link
Contributor

ebidel commented Aug 1, 2015

I'm not too family with custom endpoints. Can you generally pass objects into the request object? e.g. do they get serialized properly?

@adefran83
Copy link
Author

Yes they generally get serialized properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants