Skip to content

Commit

Permalink
Fix issue eclipse-ee4j#589 (implement skipObject() and skipArray() me…
Browse files Browse the repository at this point in the history
…thods)
  • Loading branch information
greek1979 committed Feb 24, 2023
1 parent a5b6943 commit a4d7749
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ public JsonLocation getLocation() {
throw new JsonbException("Operation not supported");
}

@Override
public void skipArray() {
if (!iterators.isEmpty()) {
JsonStructureIterator current = iterators.peek();
if (current instanceof JsonArrayIterator) {
iterators.pop();
}
}
}

@Override
public void skipObject() {
if (!iterators.isEmpty()) {
JsonStructureIterator current = iterators.peek();
if (current instanceof JsonObjectIterator) {
iterators.pop();
}
}
}

@Override
public void close() {
//noop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@

import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

import org.eclipse.yasson.adapters.AdaptersTest.StringAdapter;

import static org.eclipse.yasson.Jsonbs.*;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import jakarta.json.bind.JsonbException;
import jakarta.json.bind.annotation.JsonbTypeInfo;
import jakarta.json.bind.annotation.JsonbSubtype;

public class ObjectDeserializerTest {

Expand All @@ -42,4 +50,33 @@ public void setKey(String key) {
this.key = key;
}
}



/**
* Test for: https://github.com/eclipse-ee4j/yasson/issues/589
*/
@Test
public void testNestedUnmappedProperty() {
String json = "{\"inner\":{\"id\":123,\"_type\":\"derivationA\","
+ "\"unmapped\":{\"x\":9,\"y\":[9,8,7]},\"name\":\"abc\"}}";
Outer obj = assertDoesNotThrow(() -> defaultJsonb.fromJson(json, Outer.class));
assertEquals(123L, obj.inner.id);
assertEquals("abc", obj.inner.name);
}

// a base class
@JsonbTypeInfo(key = "_type", value = @JsonbSubtype(type = InnerBase.class, alias = "derivationA"))
public static class InnerBase {
public Long id;
public String name;
}

// derivation of the base class
public class Derivation extends InnerBase {}

// an arbitrary 'outer' root element
public static class Outer {
public InnerBase inner;
}
}

0 comments on commit a4d7749

Please sign in to comment.