Skip to content

Commit

Permalink
Merge pull request #50 from techatpark/perf-prep
Browse files Browse the repository at this point in the history
merge Perf prep to develop
  • Loading branch information
VIJAYWHAT authored Feb 26, 2024
2 parents 582939a + d4ddb14 commit ec91f1d
Show file tree
Hide file tree
Showing 19 changed files with 950 additions and 711 deletions.
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

# SJson

SJson is a **lightweight json parser for server side workloads**. It tries to get optimized memory and performance with below goals.
SJson is a **lightweight tailer made json parser for server side workloads**. It tries to get optimized memory and performance with below goals.

1. Tailermade for Serialization,Deserialization and validation.
2. Represent Json in native format.
2. No external dependencies
3. Trust the validity of json documents. It is just enough to say invalid, reasoning is optional
1. Optimized for Serialization, Deserialization and validation.
2. Represent Json in native java format.
3. No external dependencies
4. Trust the validity of json documents. It is just enough to say invalid, reasoning is optional
5. Utilize latest java features

**Note:** This is **not** general purpose parser. This is specifically written for REST API use cases.

Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<jamm.version>0.4.1</jamm.version>
<jackson.version>2.13.2.2</jackson.version>
<gson.version>2.9.0</gson.version>
<org.json.version>20220320</org.json.version>
<junit.version>5.8.2</junit.version>
<jackson.version>2.16.1</jackson.version>
<gson.version>2.10.1</gson.version>
<org.json.version>20240205</org.json.version>
<junit.version>5.10.2</junit.version>
<archunit.version>1.2.1</archunit.version>
<sonar.version>3.7.0.1746</sonar.version>
<sonar.version>3.10.0.2594</sonar.version>
<surefire.version>3.2.5</surefire.version>
<jacoco.version>0.8.11</jacoco.version>
<maven.checkstyle.version>3.3.1</maven.checkstyle.version>
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/com/techatpark/sjson/core/ArrayParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.techatpark.sjson.core;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static com.techatpark.sjson.core.util.ReaderUtil.getCharacter;

public final class ArrayParser {

/**
* util classes.
*/
private ArrayParser() {
}

/**
* Reades an Array. Reader stops at next clean character.
* @param reader
* @param contentExtractor
* @return list
* @throws IOException
*/
public static List<Object> getArray(final Reader reader,
final Json.ContentExtractor
contentExtractor) throws IOException {
final Object value = contentExtractor.getValue();
// If not Empty Array
if (value == contentExtractor) {
contentExtractor.moveCursorToNextClean();
return Collections.emptyList();
}
final List<Object> list = new ArrayList<>();
list.add(value);
while (!endOfArray(reader, contentExtractor)) {
list.add(contentExtractor.getValue());
}
contentExtractor.moveCursorToNextClean();
return list;
}
/**
* Determine array close character.
* @param reader
* @param contentExtractor
* @return flag
* @throws IOException
*/
private static boolean endOfArray(final Reader reader,
final Json.ContentExtractor
contentExtractor) throws IOException {
char character;
if (contentExtractor.getCursor() == ',') {
return false;
}
if (contentExtractor.getCursor() == ']') {
return true;
}

while ((character = getCharacter(reader.read())) != ','
&& character != ']') {
continue;
}
return character == ']';
}


}
65 changes: 65 additions & 0 deletions src/main/java/com/techatpark/sjson/core/BooleanParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.techatpark.sjson.core;

import java.io.IOException;
import java.io.Reader;

import static com.techatpark.sjson.core.util.ReaderUtil.ILLEGAL_JSON_VALUE;
import static com.techatpark.sjson.core.util.ReaderUtil.next;

/**
* Boolean Parser.
* */

public final class BooleanParser {

/**
* This is for length.
*/
public static final int THREE = 3;
/**
* This is for length.
*/
public static final int FOUR = 4;

/**
* util classes.
*/
private BooleanParser() {

}
/**
* Reads True from Reader. Reader will stip at the "e" symbol.
* @param reader
* @return string
* @throws IOException
*/
public static boolean getTrue(final Reader reader) throws IOException {
char[] charBuffer = next(reader, THREE);
if (charBuffer[0] == 'r'
&& charBuffer[1] == 'u'
&& charBuffer[2] == 'e') {
// cursor = 'e';
return true;
} else {
throw new IllegalArgumentException(ILLEGAL_JSON_VALUE);
}
}
/**
* Reads False from Reader. Reader will strip at the "e" symbol.
* @param reader
* @return string
* @throws IOException
*/
public static boolean getFalse(final Reader reader) throws IOException {
char[] charBuffer = next(reader, FOUR);
if (charBuffer[0] == 'a'
&& charBuffer[1] == 'l'
&& charBuffer[2] == 's'
&& charBuffer[THREE] == 'e') {
// cursor = 'e';
return false;
} else {
throw new IllegalArgumentException(ILLEGAL_JSON_VALUE);
}
}
}
Loading

0 comments on commit ec91f1d

Please sign in to comment.