New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate Base64 encoding/decoding of byte[]<->JSON String #452
Comments
From rmis...@google.com on May 16, 2012 06:24:37 Labels: -Milestone-CodeGenVersion1.6.0 Milestone-CodeGenVersion1.7.0 |
From yan...@google.com on May 30, 2012 15:04:20 Labels: -Milestone-CodeGenVersion1.7.0 Milestone-Version1.11.0 |
From rmis...@google.com on August 28, 2012 04:23:01 Labels: -Milestone-Version1.11.0 Milestone-Version1.12.0 |
From yan...@google.com on October 08, 2012 12:18:51 Labels: -Milestone-Version1.12.0 Milestone-Version1.13.0 |
From rmis...@google.com on December 11, 2012 05:32:52 Labels: -Milestone-Version1.13.0 Milestone-Version1.14.0 |
From yan...@google.com on January 12, 2013 07:48:09 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 Owner: yan...@google.com |
From yan...@google.com on January 14, 2013 11:54:42 we should consider storing as byte[] instead of a String Labels: -Priority-Medium Priority-High |
From yan...@google.com on January 22, 2013 06:55:17 Owner: pele...@google.com |
From pele...@google.com on January 23, 2013 10:13:25 Status: Started |
From yan...@google.com on February 09, 2013 05:25:29 Labels: -Priority-High Priority-Medium |
From yan...@google.com on March 26, 2012 11:27:03
External references, such as a standards document, or specification? https://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: http://code.google.com/p/google-api-java-client/issues/detail?id=437
The text was updated successfully, but these errors were encountered: