Skip to content

Milestone 2: Add XML.toJSONObject(...) with replacement logic and test cases #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.idea
*.iml
/target/
/src/test/resources/xml_files

/bin/
build
Expand Down
16 changes: 16 additions & 0 deletions README-M2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Milestone 2

For the Milestone 2 of SWE262P, 2 new functions were added:

```java
static JSONObject toJSONObject(Reader reader, JSONPointer path)
static JSONObject toJSONObject(Reader reader, JSONPointer path, JSONObject replacement)
```

The first one takes in 2 parameters, a `Reader` object which contains some XML input and a `JSONPointer` object that includes a json path for querying, and returns a `JSONObject` object which has the corresponding path, or throw an error if that path does not exist.

The first one takes in 3 parameters, a `Reader` object which contains some XML input and a `JSONPointer` object that includes a json path for querying, and a `JSONObject` for replacement. And returns a new `JSONObject` object which has the corresponding path replaced with the new given object, or throw an error if that path does not exist.

Both new functions are placed in the `XML.java` file.

The test cases of the functions are placed under the `org.json.junit.milestone2.tests` package, and to run the test case which deals with large file input, first create a folder named `xml_files` under the `/src/test/resources` path, and put the xml files for testing under this path.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Bug fixes, code improvements, and unit test coverage changes are welcome! Becaus
# Build Instructions

The org.json package can be built from the command line, Maven, and Gradle. The unit tests can be executed from Maven, Gradle, or individually in an IDE e.g. Eclipse.

**Building from the command line**

*Build the class files from the package root directory src/main/java*
Expand Down Expand Up @@ -83,7 +83,7 @@ java -cp .:json-java.jar Test (Unix Systems)
{"abc":"def"}
```


**Tools to build the package and execute the unit tests**

Execute the test suite with Maven:
Expand All @@ -109,6 +109,23 @@ gradlew testWithStrictMode
mvn test -P test-strict-mode
```

# Milestone 2

For the Milestone 2 of SWE262P, 2 new functions were added:

```java
static JSONObject toJSONObject(Reader reader, JSONPointer path)
static JSONObject toJSONObject(Reader reader, JSONPointer path, JSONObject replacement)
```

The first one takes in 2 parameters, a `Reader` object which contains some XML input and a `JSONPointer` object that includes a json path for querying, and returns a `JSONObject` object which has the corresponding path, or throw an error if that path does not exist.

The first one takes in 3 parameters, a `Reader` object which contains some XML input and a `JSONPointer` object that includes a json path for querying, and a `JSONObject` for replacement. And returns a new `JSONObject` object which has the corresponding path replaced with the new given object, or throw an error if that path does not exist.

Both new functions are placed in the `XML.java` file.

The test cases of the functions are placed under the `org.json.junit.milestone2.tests` package, and to run the test case which deals with large file input, first create a folder named `xml_files` under the `/src/test/resources` path, and put the xml files for testing under this path.

# Notes

For more information, please see [NOTES.md](https://github.com/stleary/JSON-java/blob/master/docs/NOTES.md)
Expand Down
Loading
Loading