5
5
import static org .junit .jupiter .api .Assertions .assertNotNull ;
6
6
7
7
import java .io .IOException ;
8
+ import java .io .StringReader ;
8
9
import java .util .Collections ;
9
10
import java .util .List ;
10
11
20
21
import jakarta .json .JsonArrayBuilder ;
21
22
import jakarta .json .JsonObjectBuilder ;
22
23
import jakarta .json .JsonValue ;
24
+ import jakarta .json .stream .JsonParser ;
23
25
24
26
@ BasicPreferences
25
27
@ Territories
@@ -29,8 +31,12 @@ class MapWithAISourceReaderTest {
29
31
void testParseSimple () throws IOException {
30
32
JsonObjectBuilder builder = Json .createObjectBuilder ();
31
33
builder .add ("nowhere" , JsonValue .NULL );
32
- try (var reader = new MapWithAISourceReader ("" )) {
33
- List <MapWithAIInfo > infoList = reader .parseJson (builder .build ());
34
+ final String json = builder .build ().toString ();
35
+ try (var reader = new MapWithAISourceReader ("" );
36
+ StringReader sr = new java .io .StringReader (json );
37
+ JsonParser parser = Json .createParser (sr )) {
38
+ parser .next ();
39
+ List <MapWithAIInfo > infoList = reader .parseJson (parser );
34
40
assertEquals (1 , infoList .size ());
35
41
assertEquals ("nowhere" , infoList .get (0 ).getName ());
36
42
}
@@ -45,9 +51,12 @@ void testParseComplex() throws IOException {
45
51
JsonArrayBuilder coCountriesArray = Json .createArrayBuilder (Collections .singleton ("addr:housenumber" ));
46
52
coCountries .add ("US-CO" , coCountriesArray .build ());
47
53
co .add ("countries" , coCountries .build ());
48
- builder .add ("Colorado" , co );
49
- try (var reader = new MapWithAISourceReader ("" )) {
50
- List <MapWithAIInfo > infoList = reader .parseJson (builder .build ());
54
+ String json = builder .add ("Colorado" , co ).build ().toString ();
55
+ try (var reader = new MapWithAISourceReader ("" );
56
+ StringReader sr = new StringReader (json );
57
+ JsonParser parser = Json .createParser (sr )) {
58
+ parser .next ();
59
+ List <MapWithAIInfo > infoList = reader .parseJson (parser );
51
60
assertEquals (1 , infoList .size ());
52
61
MapWithAIInfo info = infoList .stream ().filter (i -> "Colorado" .equals (i .getName ())).findFirst ().orElse (null );
53
62
assertNotNull (info );
0 commit comments