initial commit
This commit is contained in:
commit
a947f14f35
43 changed files with 1635 additions and 0 deletions
20
.classpath
Normal file
20
.classpath
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="src" path="src/test/java"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.4/a8762d07e76cfde2395257a5da47ba7c1dbd3dce/commons-io-1.4.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/commons-io/commons-io/1.4/48753e43ff29409fbbeadfb36186cbe27e41b179/commons-io-1.4-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.20.0-GA/a9cbcdfb7e9f86fbc74d3afae65f2248bfbf82a0/javassist-3.20.0-GA.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/org.javassist/javassist/3.20.0-GA/d8fdc08a455bc0b28bc0bed1f0d032d935cee8e1/javassist-3.20.0-GA-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-core/0.9.29/96bf09771ee37a15e8e096dbf4a586e964c2f91f/logback-core-0.9.29.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-core/0.9.29/d8fc5a9bbc78693a9cd240add2b85af10731ee47/logback-core-0.9.29-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.6.1/6f3b8a24bf970f17289b234284c94f43eb42f0e4/slf4j-api-1.6.1.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.6.1/46a386136c901748e6a3af67ebde6c22bc6b4524/slf4j-api-1.6.1-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/0.9.29/f69dbab16e4cf256bdc397d7a745e86507f3a98b/logback-classic-0.9.29.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/0.9.29/3dabd1c3a2aedb5a85cf522e4f478bb5e4156355/logback-classic-0.9.29-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/junit/junit/4.8.2/c94f54227b08100974c36170dcb53329435fe5ad/junit-4.8.2.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/junit/junit/4.8.2/cccca612a66b8387c399be31d69daf000de2ac9e/junit-4.8.2-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/org.mockito/mockito-core/1.9.5/c3264abeea62c4d2f367e21484fbb40c7e256393/mockito-core-1.9.5.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/org.mockito/mockito-core/1.9.5/46f703fb4266140c544d48a189cb25947eb6333e/mockito-core-1.9.5-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.6.1/45c37a03be19f3e0db825fd7814d0bbec40b9e0/jackson-databind-2.6.1.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-databind/2.6.1/56c55af2ce78286195b16521a82b331cc92cae0/jackson-databind-2.6.1-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.1/860340562250678d1a344907ac75754e259cdb14/hamcrest-core-1.1.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.1/2ccf1154d1a8936042a8a742dc3e611d02ac7213/hamcrest-core-1.1-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/1.0/9b473564e792c2bdf1449da1f0b1b5bff9805704/objenesis-1.0.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/1.0/b10c90e57b7bb985a7b6a704769428fe5c2a732c/objenesis-1.0-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.6.0/a0990e2e812ac6639b6ce955c91b13228500476e/jackson-annotations-2.6.0.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.6.0/7bcb615d523d88acbc121c92aafeba8d37a83792/jackson-annotations-2.6.0-sources.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="D:/gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.6.1/892d15011456ea3563319b27bdd612dbc89bb776/jackson-core-2.6.1.jar" sourcepath="D:/gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.6.1/c0063bb450c53bfa3136dc868e1062d714187e2/jackson-core-2.6.1-sources.jar"/>
|
||||
<classpathentry kind="lib" path="json-smart-1.2.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
1
.gradle/2.3/taskArtifacts/cache.properties
Normal file
1
.gradle/2.3/taskArtifacts/cache.properties
Normal file
|
|
@ -0,0 +1 @@
|
|||
#Wed Aug 12 16:00:24 CEST 2015
|
||||
BIN
.gradle/2.3/taskArtifacts/cache.properties.lock
Normal file
BIN
.gradle/2.3/taskArtifacts/cache.properties.lock
Normal file
Binary file not shown.
BIN
.gradle/2.3/taskArtifacts/fileHashes.bin
Normal file
BIN
.gradle/2.3/taskArtifacts/fileHashes.bin
Normal file
Binary file not shown.
BIN
.gradle/2.3/taskArtifacts/fileSnapshots.bin
Normal file
BIN
.gradle/2.3/taskArtifacts/fileSnapshots.bin
Normal file
Binary file not shown.
BIN
.gradle/2.3/taskArtifacts/outputFileStates.bin
Normal file
BIN
.gradle/2.3/taskArtifacts/outputFileStates.bin
Normal file
Binary file not shown.
BIN
.gradle/2.3/taskArtifacts/taskArtifacts.bin
Normal file
BIN
.gradle/2.3/taskArtifacts/taskArtifacts.bin
Normal file
Binary file not shown.
16
.project
Normal file
16
.project
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>SyntheticSerializer</name>
|
||||
<comment/>
|
||||
<projects/>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<linkedResources/>
|
||||
</projectDescription>
|
||||
13
.settings/org.eclipse.jdt.core.prefs
Normal file
13
.settings/org.eclipse.jdt.core.prefs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
#Tue Aug 18 20:35:37 CEST 2015
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
22
build.gradle
Normal file
22
build.gradle
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
repositories{
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies{
|
||||
compile 'commons-io:commons-io:1.4'
|
||||
compile 'org.javassist:javassist:3.20.0-GA'
|
||||
|
||||
compile 'ch.qos.logback:logback-core:0.9.29'
|
||||
compile 'org.slf4j:slf4j-api:1.6.1'
|
||||
compile 'ch.qos.logback:logback-classic:0.9.29'
|
||||
|
||||
testCompile 'junit:junit:4.8.2'
|
||||
testCompile 'org.mockito:mockito-core:1.9.5'
|
||||
testCompile 'com.fasterxml.jackson.core:jackson-databind:2.6.1'
|
||||
|
||||
}
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#Wed Aug 12 16:00:24 CEST 2015
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip
|
||||
164
gradlew
vendored
Normal file
164
gradlew
vendored
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
fi
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >&-
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >&-
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
90
gradlew.bat
vendored
Normal file
90
gradlew.bat
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
12
src/main/java/nl/jssl/sd/Deserializer.java
Normal file
12
src/main/java/nl/jssl/sd/Deserializer.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package nl.jssl.sd;
|
||||
|
||||
public class Deserializer {
|
||||
|
||||
public static Object deserialize(String json) {
|
||||
if (json.equals("{}")) {
|
||||
return null;
|
||||
} else
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
21
src/main/java/nl/jssl/ss/JSONSerializer.java
Normal file
21
src/main/java/nl/jssl/ss/JSONSerializer.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package nl.jssl.ss;
|
||||
|
||||
import java.util.Formatter;
|
||||
|
||||
public abstract class JSONSerializer<T> {
|
||||
protected abstract String handle(T object);
|
||||
|
||||
protected Formatter formatter = new Formatter();
|
||||
|
||||
public String toJSONString(T object) {
|
||||
if (object == null) {
|
||||
return "";
|
||||
} else if (object instanceof Number || object instanceof Boolean) {
|
||||
return "" + object.toString();
|
||||
} else if (object instanceof CharSequence || object instanceof Character) {
|
||||
return "\"" + object.toString() + "\"";
|
||||
} else {
|
||||
return handle(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
src/main/java/nl/jssl/ss/Serializer.java
Normal file
45
src/main/java/nl/jssl/ss/Serializer.java
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package nl.jssl.ss;
|
||||
|
||||
public class Serializer {
|
||||
private static SerializerFactory instance = new SynthSerializerFactory();
|
||||
|
||||
public static String toJSONString(boolean b) {
|
||||
return Boolean.toString(b);
|
||||
}
|
||||
|
||||
public static String toJSONString(short s) {
|
||||
return Short.toString(s);
|
||||
}
|
||||
|
||||
public static String toJSONString(int i) {
|
||||
return Integer.toString(i);
|
||||
}
|
||||
|
||||
public static String toJSONString(float f) {
|
||||
return Float.toString(f);
|
||||
}
|
||||
|
||||
public static String toJSONString(double d) {
|
||||
return Double.toString(d);
|
||||
}
|
||||
|
||||
public static String toJSONString(long l) {
|
||||
return Long.toString(l);
|
||||
}
|
||||
|
||||
public static String toJSONString(char c) {
|
||||
return "\"" + Character.toString(c) + "\"";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> String toJSONString(T o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return instance.createSerializer((Class<T>) o.getClass()).toJSONString(o);
|
||||
}
|
||||
|
||||
public static void setInstance(SerializerFactory instance) {
|
||||
Serializer.instance = instance;
|
||||
}
|
||||
}
|
||||
10
src/main/java/nl/jssl/ss/SerializerCreationException.java
Normal file
10
src/main/java/nl/jssl/ss/SerializerCreationException.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package nl.jssl.ss;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SerializerCreationException extends RuntimeException {
|
||||
|
||||
public SerializerCreationException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
}
|
||||
5
src/main/java/nl/jssl/ss/SerializerFactory.java
Normal file
5
src/main/java/nl/jssl/ss/SerializerFactory.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package nl.jssl.ss;
|
||||
|
||||
public interface SerializerFactory {
|
||||
public <T> JSONSerializer<T> createSerializer(Class<T> beanjavaClass);
|
||||
}
|
||||
377
src/main/java/nl/jssl/ss/SynthSerializerFactory.java
Normal file
377
src/main/java/nl/jssl/ss/SynthSerializerFactory.java
Normal file
|
|
@ -0,0 +1,377 @@
|
|||
package nl.jssl.ss;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtField;
|
||||
import javassist.CtMethod;
|
||||
import javassist.CtNewMethod;
|
||||
import javassist.Modifier;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
public class SynthSerializerFactory implements SerializerFactory {
|
||||
private static final String STRING = "java.lang.String";
|
||||
private static final String BOOLEAN = "java.lang.Boolean";
|
||||
private static final String CHARACTER = "java.lang.Character";
|
||||
private static final String BYTE = "java.lang.Byte";
|
||||
private static final String DOUBLE = "java.lang.Double";
|
||||
private static final String FLOAT = "java.lang.Float";
|
||||
private static final String LONG = "java.lang.Long";
|
||||
private static final String SHORT = "java.lang.Short";
|
||||
private static final String INTEGER = "java.lang.Integer";
|
||||
|
||||
private final static Set<String> wrappersAndString = new HashSet<String>(Arrays.asList(BOOLEAN, CHARACTER, BYTE, DOUBLE, FLOAT, LONG, SHORT, INTEGER,
|
||||
STRING));
|
||||
|
||||
private static final String COLLECTION = "java.util.Collection";
|
||||
private static final String LIST = "java.util.List";
|
||||
private static final String SET = "java.util.Set";
|
||||
private static final String MAP = "java.util.Map";
|
||||
|
||||
private static final Map<String, JSONSerializer<?>> serializers = new HashMap<>();
|
||||
private static final String ROOT_PACKAGE = "serializer.";
|
||||
|
||||
private final ClassPool pool = ClassPool.getDefault();
|
||||
private CtClass serializerBase;
|
||||
private final Map<String, CtClass> primitiveWrappers = new HashMap<String, CtClass>();
|
||||
|
||||
public SynthSerializerFactory() {
|
||||
init();
|
||||
}
|
||||
|
||||
void init() {
|
||||
try {
|
||||
serializerBase = pool.get(JSONSerializer.class.getName());
|
||||
|
||||
primitiveWrappers.put("int", pool.get(INTEGER));
|
||||
primitiveWrappers.put("short", pool.get(SHORT));
|
||||
primitiveWrappers.put("byte", pool.get(BYTE));
|
||||
primitiveWrappers.put("long", pool.get(LONG));
|
||||
primitiveWrappers.put("float", pool.get(FLOAT));
|
||||
primitiveWrappers.put("double", pool.get(DOUBLE));
|
||||
primitiveWrappers.put("boolean", pool.get(BOOLEAN));
|
||||
primitiveWrappers.put("char", pool.get(CHARACTER));
|
||||
} catch (NotFoundException e) {
|
||||
throw new SerializerCreationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> JSONSerializer<T> createSerializer(Class<T> beanjavaClass) {
|
||||
try {
|
||||
CtClass beanClass = pool.get(beanjavaClass.getName());
|
||||
|
||||
JSONSerializer<T> jsonSerializer = createSerializer(beanClass);
|
||||
|
||||
return jsonSerializer;
|
||||
} catch (NotFoundException e) {
|
||||
throw new SerializerCreationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> JSONSerializer<T> createSerializer(CtClass beanClass) {
|
||||
if (serializers.containsKey(createSerializerName(beanClass))) {
|
||||
return (JSONSerializer<T>) serializers.get(createSerializerName(beanClass));
|
||||
}
|
||||
try {
|
||||
return tryCreateSerializer(beanClass);
|
||||
} catch (NotFoundException | CannotCompileException | InstantiationException | IllegalAccessException e) {
|
||||
throw new SerializerCreationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> JSONSerializer<T> tryCreateSerializer(CtClass beanClass) throws NotFoundException, CannotCompileException, InstantiationException,
|
||||
IllegalAccessException {
|
||||
CtClass serializerClass = pool.makeClass(createSerializerName(beanClass), serializerBase);
|
||||
|
||||
addToJsonStringMethod(beanClass, serializerClass);
|
||||
|
||||
JSONSerializer<T> jsonSerializer = createSerializerInstance(serializerClass);
|
||||
|
||||
serializers.put(createSerializerName(beanClass), jsonSerializer);
|
||||
return jsonSerializer;
|
||||
}
|
||||
|
||||
/*
|
||||
* create method source, compile it and add it to the class under construction
|
||||
*/
|
||||
private void addToJsonStringMethod(CtClass beanClass, CtClass serializerClass) throws NotFoundException, CannotCompileException {
|
||||
serializerClass.addMethod(CtNewMethod.make(createToJSONStringMethodSource(beanClass), serializerClass));
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates the source, handling the for JSON different types of classes
|
||||
*/
|
||||
private <T> String createToJSONStringMethodSource(CtClass beanClass) throws NotFoundException {
|
||||
String source = "public String handle(Object object){\n";
|
||||
if (beanClass.isArray()) {
|
||||
source += "\tObject[] array=(Object[])object;\n";
|
||||
source += handleArray(beanClass);
|
||||
} else if (isCollection(beanClass)) {
|
||||
source += "\tObject[] array=((java.util.Collection)object).toArray();\n";
|
||||
source += handleArray(beanClass);
|
||||
} else if (isMap(beanClass)) {
|
||||
source += handleMap(beanClass);
|
||||
} else if (!isPrimitiveOrWrapperOrString(beanClass)) {
|
||||
List<CtMethod> getters = getGetters(beanClass);
|
||||
if (shouldAddGetterCallers(getters)) {
|
||||
source = addGetterCallers(beanClass, source, getters);
|
||||
}
|
||||
} else {
|
||||
source += "\treturn \"\";}";
|
||||
}
|
||||
System.out.println(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
/*
|
||||
* Any Collection is converted to an array, after which code is generated to handle the single elements.
|
||||
*
|
||||
* A subserializer is created for every single element, but most of the time it will be the same cached instance.
|
||||
*
|
||||
* The generated code fills a StringBuilder. The values are generated by the subserializers
|
||||
*/
|
||||
private String handleArray(CtClass beanClass) {
|
||||
String source = "\tStringBuilder result=new StringBuilder(\"[\");\n";
|
||||
source += "\tfor (int i=0; i<array.length; i++){\n";
|
||||
source += "\t\tresult.append(" + Serializer.class.getName() + ".toJSONString(array[i]));\n";
|
||||
source += "\t\tresult.append(\", \");\n";
|
||||
source += "\t};\n";
|
||||
source += "\tresult.setLength(result.length()-2);\n";
|
||||
source += "\tresult.append(\"]\");\n";
|
||||
source += "\treturn result.toString();\n";
|
||||
source += "}";
|
||||
return source;
|
||||
}
|
||||
|
||||
private String handleMap(CtClass beanClass) {
|
||||
String source = "StringBuilder result=new StringBuilder(\"{\");\n";
|
||||
source += "\tfor (java.util.Iterator entries=((java.util.Map)object).entrySet().iterator();entries.hasNext();){\n";
|
||||
source += "\t\tjava.util.Map.Entry entry=(java.util.Map.Entry)entries.next();\n";
|
||||
source += "\t\tresult.append(\"\\\"\"+entry.getKey().toString()+\"\\\"\");\n";
|
||||
source += "\t\tresult.append(\": \");\n";
|
||||
source += "\t\tresult.append(" + Serializer.class.getName() + ".toJSONString(entry.getValue()));\n";
|
||||
source += "\t\tresult.append(\", \");\n";
|
||||
source += "\t};\n";
|
||||
source += "\tresult.setLength(result.length()-2);\n";
|
||||
source += "\tresult.append(\"}\");\n";
|
||||
source += "\treturn result.toString();\n";
|
||||
source += "}";
|
||||
return source;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the class contains fields for which public getters are available, then these will be called in the generated code.
|
||||
*/
|
||||
private String addGetterCallers(CtClass beanClass, String source, List<CtMethod> getters) throws NotFoundException {
|
||||
int index = 0;
|
||||
source += "\treturn ";
|
||||
source += "\"{";
|
||||
for (CtMethod getter : getters) {
|
||||
source = addPair(beanClass, source, getter);
|
||||
if (index++ < getters.size() - 1) {
|
||||
source += ",";
|
||||
}
|
||||
}
|
||||
source += "}\";\n}";
|
||||
return source;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> JSONSerializer<T> createSerializerInstance(CtClass serializerClass) throws InstantiationException, IllegalAccessException,
|
||||
CannotCompileException {
|
||||
return (JSONSerializer<T>) serializerClass.toClass().newInstance();
|
||||
}
|
||||
|
||||
/*
|
||||
* custom root package is prepended to avoid the java.lang class in which it's illegal to create new classes
|
||||
*
|
||||
* Array marks ( '[]' ) are replaced by the 'Array', Otherwise the SerializerClassName would be syntactically incorrect
|
||||
*/
|
||||
public String createSerializerName(CtClass beanClass) {
|
||||
return createSerializerName(beanClass.getName());
|
||||
}
|
||||
|
||||
public String createSerializerName(String name) {
|
||||
return ROOT_PACKAGE + name.replaceAll("\\[\\]", "Array") + "Serializer";
|
||||
}
|
||||
|
||||
private boolean isCollection(CtClass beanClass) throws NotFoundException {
|
||||
List<CtClass> interfaces = new ArrayList<CtClass>(Arrays.asList(beanClass.getInterfaces()));
|
||||
interfaces.add(beanClass);
|
||||
for (CtClass interfaze : interfaces) {
|
||||
if (interfaze.getName().equals(COLLECTION) || interfaze.getName().equals(LIST) || interfaze.getName().equals(SET)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isMap(CtClass beanClass) throws NotFoundException {
|
||||
List<CtClass> interfaces = new ArrayList<CtClass>(Arrays.asList(beanClass.getInterfaces()));
|
||||
interfaces.add(beanClass);
|
||||
for (CtClass interfaze : interfaces) {
|
||||
if (interfaze.getName().equals(MAP)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* The JSON vernacular for key:value is pair...
|
||||
*/
|
||||
private String addPair(CtClass classToSerialize, String source, CtMethod getter) throws NotFoundException {
|
||||
source += jsonKey(getter);
|
||||
source += ": "; // what is the rule when it comes to spaces in json?
|
||||
source += jsonValue(classToSerialize, getter);
|
||||
return source;
|
||||
}
|
||||
|
||||
/*
|
||||
* derive property key from getter
|
||||
*/
|
||||
private String jsonKey(CtMethod getter) {
|
||||
return "\\\"" + toFieldName(getter.getName()) + "\\\"";
|
||||
}
|
||||
|
||||
private String jsonValue(CtClass classToSerialize, CtMethod getter) throws NotFoundException {
|
||||
String source = "";
|
||||
CtClass returnType = getter.getReturnType();
|
||||
|
||||
/* primitives are wrapped so the produced methods adhere to the JSONSerializer interface */
|
||||
source = createSubSerializerForReturnTypeAndAddInvocationToSource(classToSerialize, getter, source, returnType);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
private String createSubSerializerForReturnTypeAndAddInvocationToSource(CtClass classToSerialize, CtMethod getter, String source, CtClass returnType) {
|
||||
/* NB there does not seem to be auto(un))boxing nor generic types (or other jdk1.5 stuff) in javassist compileable code */
|
||||
|
||||
source += "\"+" + Serializer.class.getName() + ".toJSONString(";
|
||||
|
||||
// cast because of lack of generics
|
||||
source += "(" + cast(regularClassname(classToSerialize.getName())) + "object)." + getter.getName() + "()";
|
||||
|
||||
source += ")+\"";
|
||||
return source;
|
||||
}
|
||||
|
||||
/*
|
||||
* turns for example 'getValue' into 'value'
|
||||
*/
|
||||
private String toFieldName(String name) {
|
||||
return name.substring(3, 4).toLowerCase() + (name.length() > 4 ? name.substring(4) : "");
|
||||
}
|
||||
|
||||
public String regularClassname(String name) {
|
||||
return name.replaceAll("\\$", ".");
|
||||
}
|
||||
|
||||
private String cast(String classToSerialize) {
|
||||
return "(" + classToSerialize + ")";
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieves getter methods from a class
|
||||
*/
|
||||
private List<CtMethod> getGetters(CtClass beanClass) {
|
||||
List<CtMethod> methods = new ArrayList<CtMethod>();
|
||||
List<CtField> fields = getAllFields(beanClass);
|
||||
for (CtField field : fields) {
|
||||
try {
|
||||
CtMethod method = beanClass.getMethod(getGetterMethod(field), getDescription(field));
|
||||
if (Modifier.isPublic(method.getModifiers())) {
|
||||
methods.add(method);
|
||||
}
|
||||
} catch (NotFoundException n) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return methods;
|
||||
}
|
||||
|
||||
private String getGetterMethod(CtField field) {
|
||||
return "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
|
||||
}
|
||||
|
||||
private List<CtField> getAllFields(CtClass beanClass) {
|
||||
try {
|
||||
List<CtField> allfields = new ArrayList<>();
|
||||
for (CtField field : beanClass.getDeclaredFields()) {
|
||||
allfields.add(field);
|
||||
}
|
||||
if (beanClass.getSuperclass() != null) {
|
||||
return getAllFields(beanClass.getSuperclass(), allfields);
|
||||
}
|
||||
return allfields;
|
||||
} catch (NotFoundException e) {
|
||||
throw new SerializerCreationException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<CtField> getAllFields(CtClass beanClass, List<CtField> allfields) {
|
||||
for (CtField field : beanClass.getDeclaredFields()) {
|
||||
allfields.add(field);
|
||||
}
|
||||
|
||||
return allfields;
|
||||
}
|
||||
|
||||
/*
|
||||
* is getter list is not empty then callers should be added
|
||||
*/
|
||||
boolean shouldAddGetterCallers(List<CtMethod> getters) {
|
||||
return !getters.isEmpty();
|
||||
}
|
||||
|
||||
String getDescription(CtField field) throws NotFoundException {
|
||||
if (field.getType().isArray()) {
|
||||
return "()[" + innerClassName(field.getType().getName()) + ";";
|
||||
} else if (!field.getType().isPrimitive()) {
|
||||
return "()" + innerClassName(field.getType().getName()) + ";";
|
||||
} else {
|
||||
|
||||
return "()" + asPrimitive(field.getType().getName());
|
||||
}
|
||||
}
|
||||
|
||||
String asPrimitive(String name) {
|
||||
switch (name) {
|
||||
case "int":
|
||||
return "I";
|
||||
case "byte":
|
||||
return "B";
|
||||
case "float":
|
||||
return "F";
|
||||
case "long":
|
||||
return "J";
|
||||
case "boolean":
|
||||
return "Z";
|
||||
case "char":
|
||||
return "C";
|
||||
case "double":
|
||||
return "D";
|
||||
case "short":
|
||||
return "S";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
String innerClassName(String name) {
|
||||
return "L" + name.replaceAll("\\.", "/").replaceAll("\\[\\]", "");
|
||||
}
|
||||
|
||||
static boolean isPrimitiveOrWrapperOrString(CtClass beanClass) {
|
||||
return beanClass.isPrimitive() || wrappersAndString.contains(beanClass.getName());
|
||||
}
|
||||
}
|
||||
12
src/test/java/nl/jssl/sd/EmptyTest.java
Normal file
12
src/test/java/nl/jssl/sd/EmptyTest.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package nl.jssl.sd;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class EmptyTest {
|
||||
@Test
|
||||
public void null_shouldReturnEmpty() {
|
||||
assertEquals(null, Deserializer.deserialize("{}"));
|
||||
}
|
||||
}
|
||||
13
src/test/java/nl/jssl/sd/IntegerTest.java
Normal file
13
src/test/java/nl/jssl/sd/IntegerTest.java
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package nl.jssl.sd;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntegerTest {
|
||||
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals(1, Deserializer.deserialize("1"));
|
||||
}
|
||||
}
|
||||
12
src/test/java/nl/jssl/sd/StringTest.java
Normal file
12
src/test/java/nl/jssl/sd/StringTest.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package nl.jssl.sd;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringTest {
|
||||
@Test
|
||||
public void shouldReturnStringvalue() {
|
||||
assertEquals("test", Deserializer.deserialize("\"test\""));
|
||||
}
|
||||
}
|
||||
51
src/test/java/nl/jssl/ss/StringPropertyTest.java
Normal file
51
src/test/java/nl/jssl/ss/StringPropertyTest.java
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package nl.jssl.ss;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringPropertyTest {
|
||||
|
||||
@Test
|
||||
public void stringValue() {
|
||||
assertEquals("\"value\"", Serializer.toJSONString("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringProperty() {
|
||||
Bean object = new Bean();
|
||||
object.setData1("value1");
|
||||
object.setData2("value2");
|
||||
assertEquals("{\"data1\": \"value1\",\"data2\": \"value2\"}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringPropertyNull() {
|
||||
Bean object = new Bean();
|
||||
object.setData1("value1");
|
||||
object.setData2("null");
|
||||
assertEquals("{\"data1\": \"value1\",\"data2\": \"null\"}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private String data1;
|
||||
private String data2;
|
||||
|
||||
public String getData1() {
|
||||
return data1;
|
||||
}
|
||||
|
||||
public void setData1(String data1) {
|
||||
this.data1 = data1;
|
||||
}
|
||||
|
||||
public String getData2() {
|
||||
return data2;
|
||||
}
|
||||
|
||||
public void setData2(String data2) {
|
||||
this.data2 = data2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
34
src/test/java/nl/jssl/ss/collections/ArrayTest.java
Normal file
34
src/test/java/nl/jssl/ss/collections/ArrayTest.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package nl.jssl.ss.collections;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ArrayTest {
|
||||
@Test
|
||||
public void testValue() {
|
||||
assertEquals("[\"value1\", \"value2\"]", Serializer.toJSONString(new String[] { "value1", "value2" }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyValue() {
|
||||
Bean object = new Bean();
|
||||
object.setArray(new String[] { "value1", "value2" });
|
||||
assertEquals("{\"array\": [\"value1\", \"value2\"]}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private String[] array;
|
||||
|
||||
public String[] getArray() {
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setArray(String[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
41
src/test/java/nl/jssl/ss/collections/ListTest.java
Normal file
41
src/test/java/nl/jssl/ss/collections/ListTest.java
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package nl.jssl.ss.collections;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ListTest {
|
||||
@Test
|
||||
public void testValue() {
|
||||
List<String> list = new ArrayList();
|
||||
list.add("value1");
|
||||
list.add("value2");
|
||||
assertEquals("[\"value1\", \"value2\"]", Serializer.toJSONString(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyValue() {
|
||||
Bean object = new Bean();
|
||||
object.setArray(new String[] { "value1", "value2" });
|
||||
assertEquals("{\"array\": [\"value1\", \"value2\"]}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private String[] array;
|
||||
|
||||
public String[] getArray() {
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setArray(String[] array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
59
src/test/java/nl/jssl/ss/collections/MapTest.java
Normal file
59
src/test/java/nl/jssl/ss/collections/MapTest.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package nl.jssl.ss.collections;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import nl.jssl.ss.SerializerCreationException;
|
||||
import nl.jssl.ss.Serializer;
|
||||
import nl.jssl.ss.SynthSerializerFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class MapTest {
|
||||
@Test
|
||||
public void testValue() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("key1", "value1");
|
||||
map.put("key2", "value2");
|
||||
String jsonString = Serializer.toJSONString(map);
|
||||
assertTrue("{\"key1\": \"value1\", \"key2\": \"value2\"}".equals(jsonString) || "{\"key2\": \"value2\", \"key1\": \"value1\"}".equals(jsonString));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyValue() {
|
||||
Bean object = new Bean();
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("key1", "value1");
|
||||
map.put("key2", "value2");
|
||||
object.setMap(map);
|
||||
String jsonString = Serializer.toJSONString(object);
|
||||
assertTrue("{\"map\": {\"key1\": \"value1\", \"key2\": \"value2\"}}".equals(jsonString)
|
||||
|| "{\"map\": {\"key2\": \"value2\", \"key1\": \"value1\"}}".equals(jsonString));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pumpUpTheVolume() {
|
||||
Serializer.setInstance(new SynthSerializerFactory());
|
||||
try {
|
||||
throw new SerializerCreationException(new Exception());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
|
||||
private Map<String, String> map;
|
||||
|
||||
public Map<String, String> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map<String, String> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
43
src/test/java/nl/jssl/ss/collections/SetTest.java
Normal file
43
src/test/java/nl/jssl/ss/collections/SetTest.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package nl.jssl.ss.collections;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SetTest {
|
||||
@Test
|
||||
public void testValue() {
|
||||
Set<String> list = new HashSet<String>();
|
||||
list.add("value1");
|
||||
list.add("value2");
|
||||
String jsonString = Serializer.toJSONString(list);
|
||||
assertTrue("[\"value2\", \"value1\"]".equals(jsonString) || "[\"value1\", \"value2\"]".equals(jsonString));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyValue() {
|
||||
Bean object = new Bean();
|
||||
object.setSet(new HashSet<String>(Arrays.asList("value1", "value2")));
|
||||
String jsonString = Serializer.toJSONString(object);
|
||||
assertTrue("{\"set\": [\"value2\", \"value1\"]}".equals(jsonString) || "{\"set\": [\"value1\", \"value2\"]}".equals(jsonString));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private Set<String> set;
|
||||
|
||||
public Set<String> getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
public void setSet(Set<String> set) {
|
||||
this.set = set;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
48
src/test/java/nl/jssl/ss/nested/Bean1.java
Normal file
48
src/test/java/nl/jssl/ss/nested/Bean1.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package nl.jssl.ss.nested;
|
||||
|
||||
public class Bean1 {
|
||||
private String data1;
|
||||
private Bean2 bean2;
|
||||
|
||||
public String getData1() {
|
||||
return data1;
|
||||
}
|
||||
|
||||
public void setData1(String data1) {
|
||||
this.data1 = data1;
|
||||
}
|
||||
|
||||
public Bean2 getBean2() {
|
||||
return bean2;
|
||||
}
|
||||
|
||||
public void setBean2(Bean2 bean2) {
|
||||
this.bean2 = bean2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((data1 == null) ? 0 : data1.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Bean1 other = (Bean1) obj;
|
||||
if (data1 == null) {
|
||||
if (other.data1 != null)
|
||||
return false;
|
||||
} else if (!data1.equals(other.data1))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
13
src/test/java/nl/jssl/ss/nested/Bean2.java
Normal file
13
src/test/java/nl/jssl/ss/nested/Bean2.java
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package nl.jssl.ss.nested;
|
||||
|
||||
public class Bean2 {
|
||||
private String data2;
|
||||
|
||||
public String getData2() {
|
||||
return data2;
|
||||
}
|
||||
|
||||
public void setData2(String data2) {
|
||||
this.data2 = data2;
|
||||
}
|
||||
}
|
||||
14
src/test/java/nl/jssl/ss/nested/Bean2Child.java
Normal file
14
src/test/java/nl/jssl/ss/nested/Bean2Child.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package nl.jssl.ss.nested;
|
||||
|
||||
public class Bean2Child extends Bean2 {
|
||||
private String data3;
|
||||
|
||||
public String getData3() {
|
||||
return data3;
|
||||
}
|
||||
|
||||
public void setData3(String data3) {
|
||||
this.data3 = data3;
|
||||
}
|
||||
|
||||
}
|
||||
37
src/test/java/nl/jssl/ss/nested/NestedBeanTest.java
Normal file
37
src/test/java/nl/jssl/ss/nested/NestedBeanTest.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package nl.jssl.ss.nested;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class NestedBeanTest {
|
||||
@Test
|
||||
public void testBeans() {
|
||||
Bean1 object1 = new Bean1();
|
||||
object1.setData1("value1");
|
||||
Bean2 object2 = new Bean2();
|
||||
object2.setData2("value2");
|
||||
object1.setBean2(object2);
|
||||
assertEquals("{\"data1\": \"value1\",\"bean2\": {\"data2\": \"value2\"}}", Serializer.toJSONString(object1));
|
||||
assertEquals("{\"data1\": \"value1\",\"bean2\": {\"data2\": \"value2\"}}", Serializer.toJSONString(object1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullValueForBean() {
|
||||
Bean1 object1 = new Bean1();
|
||||
object1.setData1("value1");
|
||||
assertEquals("{\"data1\": \"value1\",\"bean2\": null}", Serializer.toJSONString(object1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanChildren() {
|
||||
Bean1 object1 = new Bean1();
|
||||
object1.setData1("value1");
|
||||
Bean2Child object3 = new Bean2Child();
|
||||
object3.setData2("value2");
|
||||
object3.setData3("value3");
|
||||
object1.setBean2(object3);
|
||||
assertEquals("{\"data1\": \"value1\",\"bean2\": {\"data3\": \"value3\",\"data2\": \"value2\"}}", Serializer.toJSONString(object1));
|
||||
}
|
||||
}
|
||||
63
src/test/java/nl/jssl/ss/performance/Jackson.java
Normal file
63
src/test/java/nl/jssl/ss/performance/Jackson.java
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
package nl.jssl.ss.performance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import nl.jssl.ss.Serializer;
|
||||
import nl.jssl.ss.nested.Bean1;
|
||||
import nl.jssl.ss.nested.Bean2;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class Jackson {
|
||||
List<String> trashbin = new ArrayList<String>();
|
||||
|
||||
@Test
|
||||
public void jackson() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Bean1 bean1 = new Bean1();
|
||||
Bean2 bean2 = new Bean2();
|
||||
bean1.setData1(UUID.randomUUID().toString());
|
||||
bean1.setBean2(bean2);
|
||||
bean2.setData2(UUID.randomUUID().toString());
|
||||
String valueAsString = objectMapper.writeValueAsString(bean1);
|
||||
String jsonString = Serializer.toJSONString(bean1);
|
||||
|
||||
for (int c = 0; c < 20; c++) {
|
||||
trashbin.clear();
|
||||
System.gc();
|
||||
long t0 = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
bean1 = new Bean1();
|
||||
bean2 = new Bean2();
|
||||
bean1.setData1(UUID.randomUUID().toString());
|
||||
bean1.setBean2(bean2);
|
||||
bean2.setData2(UUID.randomUUID().toString());
|
||||
valueAsString = objectMapper.writeValueAsString(bean1);
|
||||
// System.out.println(valueAsString);
|
||||
trashbin.add(valueAsString);
|
||||
}
|
||||
System.out.print(System.currentTimeMillis() - t0);
|
||||
System.out.print(",");
|
||||
trashbin.clear();
|
||||
System.gc();
|
||||
long tt0 = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
bean1 = new Bean1();
|
||||
bean2 = new Bean2();
|
||||
bean1.setData1(UUID.randomUUID().toString());
|
||||
bean1.setBean2(bean2);
|
||||
bean2.setData2(UUID.randomUUID().toString());
|
||||
jsonString = Serializer.toJSONString(bean1);
|
||||
// System.out.println(jsonString);
|
||||
trashbin.add(jsonString);
|
||||
}
|
||||
System.out.println(System.currentTimeMillis() - tt0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
54
src/test/java/nl/jssl/ss/performance/SmartJson.java
Normal file
54
src/test/java/nl/jssl/ss/performance/SmartJson.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package nl.jssl.ss.performance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minidev.json.JSONValue;
|
||||
import nl.jssl.ss.Serializer;
|
||||
import nl.jssl.ss.nested.Bean1;
|
||||
import nl.jssl.ss.nested.Bean2;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class SmartJson {
|
||||
public void jackson() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Bean1 bean1 = new Bean1();
|
||||
Bean2 bean2 = new Bean2();
|
||||
bean1.setData1(UUID.randomUUID().toString());
|
||||
bean1.setBean2(bean2);
|
||||
bean2.setData2(UUID.randomUUID().toString());
|
||||
|
||||
Serializer.toJSONString(bean1);
|
||||
JSONValue.toJSONString(bean1);
|
||||
for (int c = 0; c < 200; c++) {
|
||||
System.gc();
|
||||
long t0 = System.currentTimeMillis();
|
||||
List<String> trashbin = new ArrayList<String>();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
bean1.setData1(UUID.randomUUID().toString());
|
||||
bean1.setBean2(bean2);
|
||||
bean2.setData2(UUID.randomUUID().toString());
|
||||
String valueAsString = JSONValue.toJSONString(bean1);
|
||||
trashbin.add(valueAsString);
|
||||
}
|
||||
System.out.print(System.currentTimeMillis() - t0);
|
||||
System.out.print(",");
|
||||
trashbin.clear();
|
||||
System.gc();
|
||||
long tt0 = System.currentTimeMillis();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
bean1.setData1(UUID.randomUUID().toString());
|
||||
bean1.setBean2(bean2);
|
||||
bean2.setData2(UUID.randomUUID().toString());
|
||||
String jsonString = Serializer.toJSONString(bean1);
|
||||
// System.out.println(jsonString);
|
||||
trashbin.add(jsonString);
|
||||
}
|
||||
System.out.println(System.currentTimeMillis() - tt0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
39
src/test/java/nl/jssl/ss/primitives/BooleanPropertyTest.java
Normal file
39
src/test/java/nl/jssl/ss/primitives/BooleanPropertyTest.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BooleanPropertyTest {
|
||||
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("false", Serializer.toJSONString(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
assertEquals("false", Serializer.toJSONString(Boolean.FALSE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperty() {
|
||||
Bean object = new Bean();
|
||||
object.setData(true);
|
||||
assertEquals("{\"data\": true}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private boolean data;
|
||||
|
||||
public boolean getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(boolean data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
38
src/test/java/nl/jssl/ss/primitives/BytePropertyTest.java
Normal file
38
src/test/java/nl/jssl/ss/primitives/BytePropertyTest.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BytePropertyTest {
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("-55", Serializer.toJSONString((byte) -55));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
assertEquals("55", Serializer.toJSONString((byte) 55));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperty() {
|
||||
Bean object = new Bean();
|
||||
object.setData((byte) 1);
|
||||
assertEquals("{\"data\": 1}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private byte data;
|
||||
|
||||
public byte getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(byte data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
38
src/test/java/nl/jssl/ss/primitives/CharPropertyTest.java
Normal file
38
src/test/java/nl/jssl/ss/primitives/CharPropertyTest.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CharPropertyTest {
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("\"d\"", Serializer.toJSONString('d'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
assertEquals("\"s\"", Serializer.toJSONString('s'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperty() {
|
||||
Bean object = new Bean();
|
||||
object.setData('a');
|
||||
assertEquals("{\"data\": \"a\"}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private char data;
|
||||
|
||||
public char getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(char data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
38
src/test/java/nl/jssl/ss/primitives/DoublePropertyTest.java
Normal file
38
src/test/java/nl/jssl/ss/primitives/DoublePropertyTest.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DoublePropertyTest {
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("-55.6", Serializer.toJSONString(-55.6D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
assertEquals("55.0", Serializer.toJSONString(Double.valueOf("55.0")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperty() {
|
||||
Bean object = new Bean();
|
||||
object.setData(326.2D);
|
||||
assertEquals("{\"data\": 326.2}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private double data;
|
||||
|
||||
public double getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(double data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
38
src/test/java/nl/jssl/ss/primitives/FloatPropertyTest.java
Normal file
38
src/test/java/nl/jssl/ss/primitives/FloatPropertyTest.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FloatPropertyTest {
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("-55.6", Serializer.toJSONString(-55.6F));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
assertEquals("55.0", Serializer.toJSONString(Float.valueOf("55.0")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperty() {
|
||||
Bean object = new Bean();
|
||||
object.setData(1F);
|
||||
assertEquals("{\"data\": 1.0}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private float data;
|
||||
|
||||
public float getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(float data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
39
src/test/java/nl/jssl/ss/primitives/IntPropertyTest.java
Normal file
39
src/test/java/nl/jssl/ss/primitives/IntPropertyTest.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class IntPropertyTest {
|
||||
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("-55", Serializer.toJSONString(-55));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
assertEquals("55", Serializer.toJSONString(Integer.valueOf("55")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyValue() {
|
||||
Bean object = new Bean();
|
||||
object.setData(1);
|
||||
assertEquals("{\"data\": 1}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private int data;
|
||||
|
||||
public int getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(int data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
38
src/test/java/nl/jssl/ss/primitives/LongPropertyTest.java
Normal file
38
src/test/java/nl/jssl/ss/primitives/LongPropertyTest.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class LongPropertyTest {
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("-55", Serializer.toJSONString(-55L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
assertEquals("55", Serializer.toJSONString(Long.valueOf("55")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperty() {
|
||||
Bean object = new Bean();
|
||||
object.setData(1L);
|
||||
assertEquals("{\"data\": 1}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private long data;
|
||||
|
||||
public long getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(long data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
33
src/test/java/nl/jssl/ss/primitives/NullPropertyTest.java
Normal file
33
src/test/java/nl/jssl/ss/primitives/NullPropertyTest.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class NullPropertyTest {
|
||||
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("null", Serializer.toJSONString(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperty() {
|
||||
Bean object = new Bean();
|
||||
assertEquals("{\"data\": null}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private String data;
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
38
src/test/java/nl/jssl/ss/primitives/ShortPropertyTest.java
Normal file
38
src/test/java/nl/jssl/ss/primitives/ShortPropertyTest.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package nl.jssl.ss.primitives;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import nl.jssl.ss.Serializer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ShortPropertyTest {
|
||||
@Test
|
||||
public void testPrimitive() {
|
||||
assertEquals("-55", Serializer.toJSONString((short) -55));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrapper() {
|
||||
assertEquals("5", Serializer.toJSONString(Short.valueOf("5")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperty() {
|
||||
Bean object = new Bean();
|
||||
object.setData((short) 3);
|
||||
assertEquals("{\"data\": 3}", Serializer.toJSONString(object));
|
||||
}
|
||||
|
||||
public class Bean {
|
||||
private short data;
|
||||
|
||||
public short getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(short data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue