Skip to content
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

Closed
wonderfly opened this issue Jan 10, 2015 · 10 comments
Closed

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

wonderfly opened this issue Jan 10, 2015 · 10 comments
Assignees
Labels
imported priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@wonderfly
Copy link
Contributor

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

@wonderfly wonderfly added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. imported priority: p2 Moderately-important priority. Fix may not be included in next release. 2–5 stars labels Jan 10, 2015
@wonderfly wonderfly self-assigned this Jan 10, 2015
@wonderfly
Copy link
Contributor Author

From rmis...@google.com on May 16, 2012 06:24:37

Labels: -Milestone-CodeGenVersion1.6.0 Milestone-CodeGenVersion1.7.0

@wonderfly
Copy link
Contributor Author

From yan...@google.com on May 30, 2012 15:04:20

Labels: -Milestone-CodeGenVersion1.7.0 Milestone-Version1.11.0

@wonderfly
Copy link
Contributor Author

From rmis...@google.com on August 28, 2012 04:23:01

Labels: -Milestone-Version1.11.0 Milestone-Version1.12.0

@wonderfly
Copy link
Contributor Author

From yan...@google.com on October 08, 2012 12:18:51

Labels: -Milestone-Version1.12.0 Milestone-Version1.13.0

@wonderfly
Copy link
Contributor Author

From rmis...@google.com on December 11, 2012 05:32:52

Labels: -Milestone-Version1.13.0 Milestone-Version1.14.0

@wonderfly
Copy link
Contributor Author

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

@wonderfly
Copy link
Contributor Author

From yan...@google.com on January 22, 2013 06:55:17

Owner: pele...@google.com

@wonderfly
Copy link
Contributor Author

From pele...@google.com on January 23, 2013 10:13:25

Status: Started

@wonderfly
Copy link
Contributor Author

From yan...@google.com on February 09, 2013 05:25:29

Labels: -Priority-High Priority-Medium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

1 participant