Skip to content

Not PR: architectural concept: compact JsonValue #1394

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.nats.client.*;
import io.nats.client.support.JsonSerializable;
import io.nats.client.support.JsonValue;
import io.nats.client.support.JsonValueObject;
import io.nats.client.support.JsonValueUtils;
import io.nats.service.*;
import org.jspecify.annotations.NonNull;
Expand Down Expand Up @@ -245,7 +246,7 @@ public JsonValue toJsonValue() {
Map<String, JsonValue> map = new HashMap<>();
map.put("sdata", new JsonValue(sData));
map.put("idata", new JsonValue(iData));
return new JsonValue(map);
return new JsonValueObject(map);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/nats/client/api/AccountStatistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public AccountStatistics(Message msg) {
api = new ApiStats(readObject(jv, API));
JsonValue vTiers = readObject(jv, TIERS);
tiers = new HashMap<>();
if (vTiers.map != null) {
for (String key : vTiers.map.keySet()) {
tiers.put(key, new AccountTier(vTiers.map.get(key)));
if (vTiers.map() != null) {
for (String key : vTiers.map().keySet()) {
tiers.put(key, new AccountTier(vTiers.map().get(key)));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/nats/client/api/ApiResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ApiResponse(JsonValue jsonValue) {
}
else {
type = temp;
jv.map.remove(TYPE); // just so it's not in the toString, it's very long and the object name will be there
jv.map().remove(TYPE); // just so it's not in the toString, it's very long and the object name will be there
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/nats/client/api/ObjectMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private ObjectMeta(Builder b) {
description = readString(vObjectMeta, DESCRIPTION);
headers = new Headers();
JsonValue hJv = readObject(vObjectMeta, HEADERS);
for (String key : hJv.map.keySet()) {
for (String key : hJv.map().keySet()) {
headers.put(key, readStringList(hJv, key));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/nats/client/api/StreamState.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public class StreamState {
subjects = new ArrayList<>();
subjectMap = new HashMap<>();
JsonValue vSubjects = readValue(vStreamState, SUBJECTS);
if (vSubjects != null && vSubjects.map != null) {
for (String subject : vSubjects.map.keySet()) {
Long count = getLong(vSubjects.map.get(subject));
if (vSubjects != null && vSubjects.map() != null) {
for (String subject : vSubjects.map().keySet()) {
Long count = getLong(vSubjects.map().get(subject));
if (count != null) {
subjects.add(new Subject(subject, count));
subjectMap.put(subject, count);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/nats/client/api/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class Subject implements Comparable<Subject> {

static List<Subject> listOf(JsonValue vSubjects) {
List<Subject> list = new ArrayList<>();
if (vSubjects != null && vSubjects.map != null) {
for (String subject : vSubjects.map.keySet()) {
Long count = getLong(vSubjects.map.get(subject));
if (vSubjects != null && vSubjects.map() != null) {
for (String subject : vSubjects.map().keySet()) {
Long count = getLong(vSubjects.map().get(subject));
if (count != null) {
list.add(new Subject(subject, count));
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/io/nats/client/impl/StringListReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ abstract class StringListReader extends AbstractListReader {

List<String> strings;

StringListReader(String objectName) {
this(objectName, null);
}

StringListReader(String objectName, String filterFieldName) {
super(objectName, filterFieldName);
strings = new ArrayList<>();
Expand All @@ -34,8 +30,8 @@ abstract class StringListReader extends AbstractListReader {
@Override
void processItems(List<JsonValue> items) {
for (JsonValue v : items) {
if (v.string != null) {
strings.add(v.string);
if (v.string() != null) {
strings.add(v.string());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/nats/client/support/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private JsonValue nextValue() throws JsonParseException {
}
if (c == '{') {
nextToken();
return new JsonValue(nextObject());
return new JsonValueObject(nextObject());
}
if (c == '[') {
nextToken();
Expand Down
Loading