Gestiada / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

Add support for enums #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Allow enums to be used as types in XML representation classes.

Original issue reported on code.google.com by birgitvs...@google.com on 26 Aug 2010 at 6:04

GoogleCodeExporter commented 9 years ago
Example:
class Product {
  public enum Condition{NEW, USED, BROKEN};

  @Key("condition")
  public Condition condition;
}

Original comment by birgitvs...@google.com on 26 Aug 2010 at 6:06

GoogleCodeExporter commented 9 years ago
Problem is that we would also need to define how it gets serialized/parsed.  
For example if we wanted <condition>new</condition> to map to/from 
condition.NEW.

Another problem is that if the server adds another supported value like 
"excellent" it would break the parser.

The current best practice is to simply use String.

But I can also see the user-friendliness of supporting Java enums.  Note that 
it may be useful for both JSON and XML.

Original comment by yan...@google.com on 26 Aug 2010 at 6:27

GoogleCodeExporter commented 9 years ago
For seralization/parsing, we could possibly use the @Key annotation on enum 
values, e.g.:

public enum Condition {
  @Key("new") NEW,
  @Key("used") USED,
  @Key("broken") BROKEN
}

For the case where a value is added on the server, throwing an exception seems 
like a reasonable behavior.  Anyway, chances are that even if a String is used, 
the application like only know how to handle the set of values specified, and 
won't operate correctly if it encounters a new value.  Also, application 
writers will have a choice of enum vs. String and will be best able to make the 
trade-off between usability and flexibility.

Original comment by yan...@google.com on 20 Oct 2010 at 6:39

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 12 Nov 2010 at 1:59

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 8 Jan 2011 at 6:23

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 15 Feb 2011 at 8:30

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 11 Mar 2011 at 12:13

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 21 Apr 2011 at 4:02

GoogleCodeExporter commented 9 years ago
http://codereview.appspot.com/4437045

Original comment by yan...@google.com on 27 Apr 2011 at 1:02

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 2 May 2011 at 5:57