title: Google Cloud Datastore (not Appengine): How to set a Java collection in an Entity
body: <p>I'm using a <strong>non</strong> AppEngine Google Cloud Datastore Java API. I store entities from outside the Google Cloud environment. </p>
  
  <p>My Gradle dependency is: </p>
  
  <p><code>compile('com.google.cloud:google-cloud-datastore:0.8.0-beta')</code></p>
  
  <p>I have a List in an entity that I'd like to set in the Entity but there is no method to set a collection. Currently I'm setting values as follows: </p>
  
  <pre><code>/**
   * It returns a Google Datastore Entity from a DTO Entity
   * @param usersKey The Key to use to build the entity
   * @param user The Users entity containing the data to persist
   * @return A Google Datastore Entity from a DTO Entity
   */
  public static Entity fromDtoToGoogleEntity(Key usersKey, User user) {
  
      Entity.Builder builder = Entity.newBuilder(usersKey);
      builder.set(User.FIRST_NAME, user.getFirstName());
      builder.set(User.LAST_NAME, user.getLastName());
      builder.set(User.PASSWORD, user.getPassword());
      builder.set(User.EMAIL, user.getEmail());
      builder.set(User.STRIPE_USER_ID, user.getStripeUserId());
      builder.set(User.COUNTRY, user.getCountry());
      builder.set(User.DESCRIPTION, user.getDescription());
      builder.set(User.USERNAME, user.getUsername());
      builder.set(User.ENABLED, user.isEnabled());       
  
      return builder.build();
  
  }
  </code></pre>
  
  <p>There is no method such as: </p>
  
  <pre><code>builder.set(User.USER_ROLES, user.getUserRoles());//userRoles is a List&lt;String&gt;
  </code></pre>
  
  <p>Can anybody suggest a way? The only way so far is to have a comma separated String representation and convert from Collection to comma separated String and vice versa. </p>
  
  <p>Thanks in advance. </p>
  
  <p>M.</p>