From 58dd79803be77192c1e68aaa52e370f7bf9f9a9e Mon Sep 17 00:00:00 2001 From: magicprinc Date: Thu, 2 Dec 2021 12:44:27 +0100 Subject: [PATCH] * more informative README.md + very dirty example.json --- README.md | 101 +++++++++++------- .../org/jsoup/parser/JsonTreeBuilderTest.java | 10 +- src/test/resources/example.json | 14 ++- src/test/resources/example1.xml | 12 ++- src/test/resources/example2.xml | 5 +- 5 files changed, 87 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index cea79e6..889edab 100644 --- a/README.md +++ b/README.md @@ -13,26 +13,35 @@ No extra dependencies! [**example.json**](src/test/resources/example.json) ```json +/* +I am here: src\test\resources/example.json **/ {projects: [ -{ - project_name = 'Google Gson', - 'url': "https://github.com/google/gson", - "rating": 4.956, - "contributors": [{ - first_name: Jesse, 'last_name': 'Wilson', - "home_page": "https://medium.com/@swankjesse" - }] -},{ - "project_name" => jsoup, - "url": "https://jsoup.org", - "rating": 5e10, - "contributors": [ - { - "first_name" = "Jonathan", "last_name" => "Hedley", - "home_page": "https://jhy.io" - },{ - "first_name": "Andrej", "last_name": "Fink"; "home_page": "https://github.com/magicprinc" -}]}]} + { + project_name = 'Google Gson', + 'url': "https://github.com/google/gson", + "rating": 4.956, + "contributors": [{ + first_name: Jesse,,,, ' last name ': "'Wilson ' ", + "home_page": "https://medium.com/@swankjesse" + }] + },{ + "project_name" => jsoup + + "url": "https://jsoup.org";,;,; + + "rating"=5e10, + 'contributors': [ + { + "first_name" = "Jonathan", "last_name" => "Hedley", +"home_page": "https://jhy.io" + },{///2nd OBJ in Array + "first_name": "Andrej", "last_name": "Fink";;; " home + page ": " https://github.com/ + magicprinc "; + } + ] + } +]} ``` **java** @@ -46,34 +55,43 @@ assertEquals("truetrue< [**internal XML tree 1 (with class metadata) **](src/test/resources/example1.xml) ```xml + Google Gson https://github.com/google/gson 4.956 + Jesse - Wilson + 'Wilson ' https://medium.com/@swankjesse + jsoup https://jsoup.org 5e10 + Jonathan Hedley https://jhy.io + + Andrej Fink - https://github.com/magicprinc + https://github.com/ + magicprinc @@ -88,39 +106,40 @@ Document doc = Jsoup.parse(exampleJson, "UTF-8", "", JsonTreeBuilder.jsonParser( [**internal XML tree 2 (no metadata) **](src/test/resources/example2.xml) ```xml - - + + - Google Gson - https://github.com/google/gson - 4.956 + Google Gson + https://github.com/google/gson + 4.956 - Jesse - Wilson - https://medium.com/@swankjesse + Jesse + 'Wilson ' + https://medium.com/@swankjesse + - jsoup - https://jsoup.org - 5e10 + jsoup + https://jsoup.org + 5e10 - Jonathan - Hedley - https://jhy.io + Jonathan + Hedleyhttps://jhy.io - - Andrej - Fink - https://github.com/magicprinc + + Andrej + Fink https://github.com/ + magicprinc - - + ``` More examples are available in 135 unit-tests in [org.jsoup.parser.JsonTreeBuilderTest](/src/test/java/org/jsoup/parser/JsonTreeBuilderTest.java) \ No newline at end of file diff --git a/src/test/java/org/jsoup/parser/JsonTreeBuilderTest.java b/src/test/java/org/jsoup/parser/JsonTreeBuilderTest.java index b89a902..20bf63e 100644 --- a/src/test/java/org/jsoup/parser/JsonTreeBuilderTest.java +++ b/src/test/java/org/jsoup/parser/JsonTreeBuilderTest.java @@ -1702,12 +1702,13 @@ public void testJavaDocExample () throws Exception { Document doc = Jsoup.parse(getClass().getResourceAsStream("/example.json"), "UTF-8", "", jsonParser()); System.out.println(repeat('#', 100)+doc.html()+repeat('#', 100)); //doc.outputSettings().prettyPrint(false); - assertEquals("" + + assertEquals( + "" + "Google Gson" + "https://github.com/google/gson" + "4.956"+ "Jesse" + - "Wilson" + + "'Wilson ' " + "https://medium.com/@swankjesse" + "jsoup" + "https://jsoup.org" + @@ -1715,8 +1716,9 @@ public void testJavaDocExample () throws Exception { "Jonathan" + "Hedley" + "https://jhy.io" + - "AndrejFink" + - "https://github.com/magicprinc", doc.html()); + ""+ + "AndrejFink" + + " https://github.com/\n magicprinc ",doc.html()); assertEquals("Fink", doc.select("#contributors obj:eq(1) #last_name").text()); assertEquals("jsoup", doc.select("#projects #project_name.str.unquoted").text()); assert "Fink".equals(doc.select("#contributors obj:eq(1) #last_name").text()); diff --git a/src/test/resources/example.json b/src/test/resources/example.json index 6ec1b3a..323132a 100644 --- a/src/test/resources/example.json +++ b/src/test/resources/example.json @@ -1,10 +1,12 @@ +/* +I am here: src\test\resources/example.json **/ {projects: [ { project_name = 'Google Gson', 'url': "https://github.com/google/gson", "rating": 4.956, "contributors": [{ - first_name: Jesse,,,, 'last_name': 'Wilson', + first_name: Jesse,,,, ' last name ': "'Wilson ' ", "home_page": "https://medium.com/@swankjesse" }] },{ @@ -12,13 +14,15 @@ "url": "https://jsoup.org";,;,; - "rating": 5e10, - "contributors": [ + "rating"=5e10, + 'contributors': [ { "first_name" = "Jonathan", "last_name" => "Hedley", "home_page": "https://jhy.io" - },{ - "first_name": "Andrej", "last_name": "Fink";;; "home_page": "https://github.com/magicprinc" + },{///2nd OBJ in Array + "first_name": "Andrej", "last_name": "Fink";;; " home + page ": " https://github.com/ + magicprinc "; } ] } diff --git a/src/test/resources/example1.xml b/src/test/resources/example1.xml index dfe2e46..1d3c7cb 100644 --- a/src/test/resources/example1.xml +++ b/src/test/resources/example1.xml @@ -1,3 +1,5 @@ + @@ -15,8 +17,8 @@ Jesse - - Wilson + + 'Wilson ' https://medium.com/@swankjesse @@ -47,14 +49,16 @@ + Andrej Fink - - https://github.com/magicprinc + + https://github.com/ magicprinc diff --git a/src/test/resources/example2.xml b/src/test/resources/example2.xml index 70c9383..eba793c 100644 --- a/src/test/resources/example2.xml +++ b/src/test/resources/example2.xml @@ -1 +1,4 @@ -Google Gsonhttps://github.com/google/gson4.956JesseWilsonhttps://medium.com/@swankjessejsouphttps://jsoup.org5e10JonathanHedleyhttps://jhy.ioAndrejFinkhttps://github.com/magicprinc \ No newline at end of file +Google Gsonhttps://github.com/google/gson4.956Jesse'Wilson ' https://medium.com/@swankjessejsouphttps://jsoup.org5e10JonathanHedleyhttps://jhy.ioAndrejFink https://github.com/ + magicprinc \ No newline at end of file