qickrooms / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
0 stars 0 forks source link

Shorter JSON format for List<> of "primitive" types? #233

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When storing a List<Integer>, objectify internally stores a JSON array of 
objects, such as:

    [{"integerValue":"2837482934789","indexed":false},
    {"integerValue":"2837482934744","indexed":false}]

Wouldn't it make sense for primitive types (JSON's own data types such as 
string, number and boolean) to "shorten" this by using an Integer, String, etc. 
array:

    [2837482934789,2837482934744]

Or, to maintain compatibility, something like this:

    {
        "integerValues": {
            [2837482934789,2837482934744]
        }
    }

This would save a lot of storage space. Also, in this case the "indexed" 
property (see #232) doesn't make any sense.

Original issue reported on code.google.com by oliver.h...@gmail.com on 2 Apr 2015 at 3:17

GoogleCodeExporter commented 9 years ago
Objectify does not store JSON of anything internally. What is it you're looking 
at?

Original comment by lhori...@gmail.com on 2 Apr 2015 at 4:13

GoogleCodeExporter commented 9 years ago
Strange. Google changed their console yesterday. Before that date, List<> 
fields were opaque. Now they are shown. I probably wrongly assumed objectify 
processes my fields before it stores them.

I have the following class:

@Cache @Entity
public class Channel extends AutoId implements Serializable {
    private static final long serialVersionUID = 1;
    private Channel() {} // protect

    @ApiResourceProperty(ignored = AnnotationBoolean.TRUE) private Long created;
    @IgnoreSave(IfDefault.class) private ChannelScope scope = ChannelScope.PRIVATE;

    private List<Long> subscribedUserIds = new ArrayList<>();
    @IgnoreSave(IfEmpty.class) private List<Long> deniedUserIds = new ArrayList<>();
    @IgnoreSave(IfEmpty.class) private List<Long> invitedUserIds = new ArrayList<>();

    private String name;
    private Integer color;
    @IgnoreSave(IfNull.class) private String preview;

    @Ignore private RingTone ringer;
    @Ignore private Boolean geosensor;

    @Ignore private Integer[] boardposition;
    @Ignore private Long modified;

    // getters and setters omitted

}

subscribedUserIds is an ArrayList<Long>, which I directly save. Look at 
attached files how the result looks like in Google's new console.

Any idea where that comes from?

Original comment by oliver.h...@gmail.com on 2 Apr 2015 at 5:17

Attachments:

GoogleCodeExporter commented 9 years ago
I was thinking that maybe Google renders the list field as JSON for display.

Original comment by oliver.h...@gmail.com on 2 Apr 2015 at 6:55

GoogleCodeExporter commented 9 years ago
Data in the datastore is stored in Google's native format, which is some sort 
of protobuf. What you're seeing is an arbitrary rendering of the data in 
Google's viewer.

Original comment by lhori...@gmail.com on 2 Apr 2015 at 9:17