Objectify cannot autoconvert Strings greater than 500 characters to Text within @Embed collections

StackOverflow https://stackoverflow.com/questions/22436216

سؤال

Update:

Since I feel like I'm running out of options, it might be helpful, to find a way to parse a com.google.appengine.api.datastore.Text object. How do I represent this kind of class in json?

Original question:

I am using Objectify to handle datastore operations in Google App Engine. I have a User class, and an Event class. A User has a List of Events, thus I've added the @Embed annotation to my Event class (otherwise I would get "not a supported property type" error).

@Entity
@Embed
public class Event
{
    private String eventTitle;
    private Date eventDate;
    private int eventDuration;
    private int ticketsLeft;
    private String eventDescription;
    private int ticketPrice;
    private String location;
    private int ticketsPurchased;
    private boolean isPaid;
    private int priority;
    @Id private Long identifier;
    // ... getters/setters
}

User class:

@Entity
public class User
{
    @Id private Long identifier;
    private String username;
    private String password;
    private List<Event> orderedEvents;
    // ... getters/setters
}

I'm parsing the events from a JSON file uring gson. The eventDescription property of an event can get pretty long, and in these cases I get the error message in the title. I've also tried changing the String to Text, but I have no idea how to parse a Text object, and I keep getting "Expected BEGIN_OBJECT but was STRING" error. Is there any way around this limitation?

هل كانت مفيدة؟

المحلول 2

I have found a way to get around this problem, by doing what the error message suggests, and using a com.google.appengine.api.datastore.Text object instead of a String. When using Text, the json should look like the following:

{
    "priority": 1,
    "title": "xxxx",
    "date": "2013-12-17T19:30:00Z",
    "duration": 120,
    "tickets": 12,
    "price": 1400,
    "description": {
        "value": "long text goes here"
    },
    "location": "location"
}

نصائح أخرى

I am not sure which version of Objectify you are using currently. But as per the documentation available "String fields which store more than 500 characters (the GAE limit) are automatically converted to Text internally. "

Additionally, this has been addressed as per this discussion thread in version 4.0.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top