-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from avaje/feature/unwrap-parser
Add JsonReader.unwrap() to access underlying JsonParser when using avaje-jsonb-jackson
- Loading branch information
Showing
10 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
jsonb-jackson/src/test/java/io/avaje/jsonb/jackson/UnwrapJacksonParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.avaje.jsonb.jackson; | ||
|
||
import com.fasterxml.jackson.core.JsonLocation; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import io.avaje.jsonb.JsonReader; | ||
import io.avaje.jsonb.JsonType; | ||
import io.avaje.jsonb.Jsonb; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class UnwrapJacksonParserTest { | ||
|
||
Jsonb jsonb = Jsonb.builder().build(); | ||
|
||
@Test | ||
void unwrap() { | ||
try (JsonReader reader = jsonb.reader("{\"id\":42,\"name\":\"rob\"}")) { | ||
JsonParser jsonParser = reader.unwrap(JsonParser.class); | ||
JsonLocation location = jsonParser.currentLocation(); | ||
|
||
assertThat(location.toString()).isEqualTo("[Source: (String)\"{\"id\":42,\"name\":\"rob\"}\"; line: 1, column: 1]"); | ||
|
||
JsonType<Map<String, Object>> jsonMap = jsonb.type(Object.class).map(); | ||
|
||
Map<String, Object> map = jsonMap.fromJson(reader); | ||
assertThat(map.get("id")).isEqualTo(42D); | ||
assertThat(map.get("name")).isEqualTo("rob"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters