55import static org .junit .jupiter .api .Assertions .assertNotNull ;
66
77import java .io .IOException ;
8+ import java .io .StringReader ;
89import java .util .Collections ;
910import java .util .List ;
1011
2021import jakarta .json .JsonArrayBuilder ;
2122import jakarta .json .JsonObjectBuilder ;
2223import jakarta .json .JsonValue ;
24+ import jakarta .json .stream .JsonParser ;
2325
2426@ BasicPreferences
2527@ Territories
@@ -29,8 +31,12 @@ class MapWithAISourceReaderTest {
2931 void testParseSimple () throws IOException {
3032 JsonObjectBuilder builder = Json .createObjectBuilder ();
3133 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 );
3440 assertEquals (1 , infoList .size ());
3541 assertEquals ("nowhere" , infoList .get (0 ).getName ());
3642 }
@@ -45,9 +51,12 @@ void testParseComplex() throws IOException {
4551 JsonArrayBuilder coCountriesArray = Json .createArrayBuilder (Collections .singleton ("addr:housenumber" ));
4652 coCountries .add ("US-CO" , coCountriesArray .build ());
4753 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 );
5160 assertEquals (1 , infoList .size ());
5261 MapWithAIInfo info = infoList .stream ().filter (i -> "Colorado" .equals (i .getName ())).findFirst ().orElse (null );
5362 assertNotNull (info );
0 commit comments