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

Improvement for JSONObject class #295

Closed
kpopovic opened this issue Oct 19, 2016 · 5 comments
Closed

Improvement for JSONObject class #295

kpopovic opened this issue Oct 19, 2016 · 5 comments

Comments

@kpopovic
Copy link

Hello,
please add new methods to JSONObject class. I think the can be very useful.

byte[] getBinary(String key) / byte[] getBinary(String key, byte[] def)

JSON itself has no notion of a binary, this extension complies to the RFC-7493, so this method assumes there is a String value with the key and it contains a Base64 encoded binary, which it decodes if found and returns.

public JsonObject put(String key, byte[] value)

Put a byte[] into the JSON object with the specified key.
JSON extension RFC7493, binary will first be Base64 encoded before being put as a String.

public java.time.Instant getInstant(String key)

Get the instant value with the specified key.
JSON itself has no notion of a date, this extension complies to the RFC-7493, so this method assumes there is a String value with the key and it contains a ISODATE encoded date, which it decodes if found and returns.

example:
public Instant getInstant(String key) {
Objects.requireNonNull(key);
String encoded = (String) map.get(key);
return encoded == null ? null : Instant.from(ISO_INSTANT.parse(encoded));
}

java.time.Instant getInstant(String key, java.time.Instant def)

Like getInstant(String) but specifying a default value to return if there is no entry.

example:
public Instant getInstant(String key, Instant def) {
Objects.requireNonNull(key);
Object val = map.get(key);
return val != null || map.containsKey(key) ?
(val == null ? null : Instant.from(ISO_INSTANT.parse((String) val))) : def;
}

public JsonObject put(String key, java.time.Instant value)

Put a Instant into the JSON object with the specified key.
JSON extension RFC7493, instant will first be encoded to ISODATE String.

example:
import static java.time.format.DateTimeFormatter.ISO_INSTANT;
.....
public JsonObject put(String key, Instant value) {
Objects.requireNonNull(key);
map.put(key, value == null ? null : ISO_INSTANT.format(value));
return this;
}

public JsonObject copy()
........................................
Copy the JSON object

@johnjaylward
Copy link
Contributor

We don't currently support java8, so I don't see the Instant items being
implemented.

On Oct 19, 2016 18:03, "Krešimir Popović" notifications@github.com wrote:

Hello,
please add new methods to JSONObject class. I think the can be very useful.
byte[] getBinary(String key) / byte[] getBinary(String key, byte[] def)

JSON itself has no notion of a binary, this extension complies to the
RFC-7493, so this method assumes there is a String value with the key and
it contains a Base64 encoded binary, which it decodes if found and returns.
public JsonObject put(String key, byte[] value)

Put a byte[] into the JSON object with the specified key.
JSON extension RFC7493, binary will first be Base64 encoded before being
put as a String.
public java.time.Instant getInstant(String key)

Get the instant value with the specified key.
JSON itself has no notion of a date, this extension complies to the
RFC-7493, so this method assumes there is a String value with the key and
it contains a ISODATE encoded date, which it decodes if found and returns.

example:
public Instant getInstant(String key) {
Objects.requireNonNull(key);
String encoded = (String) map.get(key);
return encoded == null ? null : Instant.from(ISO_INSTANT.parse(encoded));
}

java.time.Instant getInstant(String key, java.time.Instant def)
Like getInstant(String) but specifying a default value to return if there
is no entry.

example:
public Instant getInstant(String key, Instant def) {
Objects.requireNonNull(key);
Object val = map.get(key);
return val != null || map.containsKey(key) ?
(val == null ? null : Instant.from(ISO_INSTANT.parse((String) val))) :
def;
}
public JsonObject put(String key, java.time.Instant value)

Put a Instant into the JSON object with the specified key.
JSON extension RFC7493, instant will first be encoded to ISODATE String.

example:
import static java.time.format.DateTimeFormatter.ISO_INSTANT;
.....
public JsonObject put(String key, Instant value) {
Objects.requireNonNull(key);
map.put(key, value == null ? null : ISO_INSTANT.format(value));
return this;
}

public JsonObject copy()
........................................
Copy the JSON object


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#295, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAXa18YBKN4_fig1hlWozCJmYCfn1KQoks5q1pO4gaJpZM4KbgcW
.

@kpopovic
Copy link
Author

Java 8 was released on 18 March 2014, more then 2 years ago...
Do you plan to support Java 8 at all ?

@johnjaylward
Copy link
Contributor

We are currently supporting java6 and up, but that means no java8 specific
features

On Oct 19, 2016 6:17 PM, "Krešimir Popović" notifications@github.com
wrote:

Java 8 was released on 18 March 2014, more then 2 years ago...
Do you plan to support Java 8 at all ?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#295 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAXa14OuCqXGY-B5_4pPKrD61Qob8qv-ks5q1pbngaJpZM4KbgcW
.

@kpopovic
Copy link
Author

Ok, I understand.

@stleary
Copy link
Owner

stleary commented Oct 20, 2016

Not adding support for date or time transforms at this time. No objection if someone sees a need for Base64 and wants to try implementing it in a way that does not impact existing applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants