fer626 / google-api-java-client

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

Generate Base64 encoding/decoding of byte[]<->JSON String #437

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
External references, such as a standards document, or specification?

http://code.google.com/apis/discovery/v1/reference.html#type-and-format-summary

Java environments (e.g. Java 6, Android 2.3, App Engine, or All)?

All

Please describe the feature requested.

Some Google API services may include a data type that is a base64-encoded 
string of bytes.  It is the data type listed in the above reference link as 
type value "string" and format value "byte".  It is not documented there, but 
apparently this is the URL-safe alphabet with padding.  We should make it 
easier to parse/serialize that format.

The catch is the lower-level JSON model doesn't have this support built-in.  
The simplest solution is to still use Java String as the data type of the 
field, but provide accessors that handle that conversion and work with byte[].

So one option:

public class A {
  @Key private String data;
  public byte[] getData() {
    return Base64.decodeBase64(data);
  }
  public void setData(byte[] data) {
    this.data = Base64.encodeBase64URLSafeString(data);
  }
}

Another option:

public class A {
  @Key private String data;
  public String getData() {
    return data;
  }
  public void setData(String data) {
    this.data = data;
  }
  public byte[] decodeData() {
    return Base64.decodeBase64(data);
  }
  public void encodeData(byte[] data) {
    this.data = Base64.encodeBase64URLSafeString(data);
  }
}

(or something along these lines)

Original issue reported on code.google.com by yan...@google.com on 26 Mar 2012 at 6:27

GoogleCodeExporter commented 9 years ago

Original comment by rmis...@google.com on 16 May 2012 at 1:24

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 30 May 2012 at 10:04

GoogleCodeExporter commented 9 years ago

Original comment by rmis...@google.com on 28 Aug 2012 at 11:23

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 8 Oct 2012 at 7:18

GoogleCodeExporter commented 9 years ago

Original comment by rmis...@google.com on 11 Dec 2012 at 1:32

GoogleCodeExporter commented 9 years ago
New reference link:

https://developers.google.com/discovery/v1/type-format?hl=en

Example use case:

https://www.googleapis.com/discovery/v1/apis/storage/v1beta2/rest?fields=schemas
/Object/properties/media/properties/data

Original comment by yan...@google.com on 12 Jan 2013 at 3:48

GoogleCodeExporter commented 9 years ago
we should consider storing as byte[] instead of a String

Original comment by yan...@google.com on 14 Jan 2013 at 7:54

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 22 Jan 2013 at 2:55

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 23 Jan 2013 at 6:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 9 Feb 2013 at 1:25