How to save a simple array of numbers on AppEngine (Java)?

5 views
Skip to first unread message

Adio via StackOverflow

unread,
Jul 3, 2013, 7:45:40 AM7/3/13
to google-appengin...@googlegroups.com

Does anyone knows how to save a simple array of number in an AppEngine Entity ?

For example if I have this object of class:

class Person {

    String name;
    Date dateOfBirth;
    int favoriteNumbers[];

    Person(String name, Date dateOfBirth, int[] favoriteNumbers) {
      this.name = name;
      this.dateOfBirth = dateOfBirth;
      this.favoriteNumbers = favoriteNumbers;
    }


  }

//save the entity ! 
     Person person = new Person("Jack", new Date(), new int[]{2, 3, 4});
     Entity entity = new Entity("person");
     entity.setProperty("name", person.name);
     entity.setProperty("dateOfBirth",person.dateOfBirth);
     entity.setProperty("favoriteNumbers",favoriteNumbers);// this here thrown an exception !




    java.lang.IllegalArgumentException: firsRound: [I is not a supported property type.
        at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:235)
        at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:207)
        at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:173)
        at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:148)
        at com.google.appengine.api.datastore.PropertyContainer.setProperty(PropertyContainer.java:101) 
.......

*Note: The code above is similar to the real. I presented this code for simplicity. *



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/17447004/how-to-save-a-simple-array-of-numbers-on-appengine-java

Loša via StackOverflow

unread,
Jul 3, 2013, 1:36:01 PM7/3/13
to google-appengin...@googlegroups.com

Try to use List instead of array.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/17447004/how-to-save-a-simple-array-of-numbers-on-appengine-java/17454543#17454543

Mark Doyle via StackOverflow

unread,
Jul 3, 2013, 2:04:31 PM7/3/13
to google-appengin...@googlegroups.com

setProperty is expecting something that extends Collection. As a quick fix something like the following will work:

Integer[] favoriteNumbers = new Integer[]{1,2,3};
entity.setProperty("favoriteNumbers", new ArrayList<Integer>(Arrays.asList(favoriteNumbers)));

However I strongly suggest that you check out a framework such as Objectify which will mean you don't manually need to form the Entity.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/17447004/how-to-save-a-simple-array-of-numbers-on-appengine-java/17455152#17455152
Reply all
Reply to author
Forward
0 new messages