Skip to content

Commit

Permalink
fixup! [eclipse-ee4j#625]Wrote the missing methods in JsonStructureTo…
Browse files Browse the repository at this point in the history
…ParserAdapter and tests for them; more fulfill of the JSON-P's JsonParser
  • Loading branch information
api-from-the-ion committed Nov 4, 2023
1 parent c90d1aa commit 2efa478
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,20 @@ public Stream<JsonValue> getArrayStream() {
JsonStructureIterator current = iterators.peek();
if (current instanceof JsonArrayIterator) {
return StreamSupport.stream(new Spliterators.AbstractSpliterator<>(Long.MAX_VALUE, ORDERED) {
public Spliterator<JsonValue> trySplit() {
return null;
}

public boolean tryAdvance(Consumer<? super JsonValue> action) {
Objects.requireNonNull(action);
if (!JsonStructureToParserAdapter.this.hasNext() || JsonStructureToParserAdapter.this.next() == Event.END_ARRAY) {
return false;
} else {
action.accept(JsonStructureToParserAdapter.this.getValue());
return true;
}
}
}, false);
public Spliterator<JsonValue> trySplit() {
return null;
}

public boolean tryAdvance(Consumer<? super JsonValue> action) {
Objects.requireNonNull(action);
if (!JsonStructureToParserAdapter.this.hasNext() || JsonStructureToParserAdapter.this.next() == Event.END_ARRAY) {
return false;
} else {
action.accept(JsonStructureToParserAdapter.this.getValue());
return true;
}
}
}, false);
} else {
throw new IllegalStateException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Outside of array context"));
}
Expand All @@ -235,34 +235,34 @@ public Stream<Map.Entry<String, JsonValue>> getObjectStream() {
JsonStructureIterator current = iterators.peek();
if (current instanceof JsonObjectIterator) {
return StreamSupport.stream(new Spliterators.AbstractSpliterator<>(Long.MAX_VALUE, ORDERED) {
public Spliterator<Map.Entry<String, JsonValue>> trySplit() {
return null;
}

public boolean tryAdvance(Consumer<? super Map.Entry<String, JsonValue>> action) {
Objects.requireNonNull(action);
if (!JsonStructureToParserAdapter.this.hasNext()) {
return false;
} else {
Event e = JsonStructureToParserAdapter.this.next();
if (e == Event.END_OBJECT) {
return false;
} else if (e != Event.KEY_NAME) {
throw new JsonException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Cannot read object key"));
} else {
String key = JsonStructureToParserAdapter.this.getString();
if (!JsonStructureToParserAdapter.this.hasNext()) {
throw new JsonException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Cannot read object value"));
} else {
JsonStructureToParserAdapter.this.next();
JsonValue value = JsonStructureToParserAdapter.this.getValue();
action.accept(new AbstractMap.SimpleImmutableEntry<>(key, value));
return true;
}
}
}
}
}, false);
public Spliterator<Map.Entry<String, JsonValue>> trySplit() {
return null;
}

public boolean tryAdvance(Consumer<? super Map.Entry<String, JsonValue>> action) {
Objects.requireNonNull(action);
if (!JsonStructureToParserAdapter.this.hasNext()) {
return false;
} else {
Event e = JsonStructureToParserAdapter.this.next();
if (e == Event.END_OBJECT) {
return false;
} else if (e != Event.KEY_NAME) {
throw new JsonException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Cannot read object key"));
} else {
String key = JsonStructureToParserAdapter.this.getString();
if (!JsonStructureToParserAdapter.this.hasNext()) {
throw new JsonException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Cannot read object value"));
} else {
JsonStructureToParserAdapter.this.next();
JsonValue value = JsonStructureToParserAdapter.this.getValue();
action.accept(new AbstractMap.SimpleImmutableEntry<>(key, value));
return true;
}
}
}
}
}, false);
} else {
throw new IllegalStateException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Outside of object context"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

package org.eclipse.yasson.customization.polymorphism;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down

0 comments on commit 2efa478

Please sign in to comment.