diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e5fdaca --- /dev/null +++ b/pom.xml @@ -0,0 +1,123 @@ + + + + 4.0.0 + + com.halo + zjson + 1.7 + + zjson + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + nexus-aliyun + nexus-aliyun + http://maven.aliyun.com/nexus/content/groups/public/ + + true + + + false + + + + + + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + false + lib/ + + + + + + + + diff --git a/src/main/java/com/halo/zjson/JSONUtils.java b/src/main/java/com/halo/zjson/JSONUtils.java new file mode 100644 index 0000000..84f369b --- /dev/null +++ b/src/main/java/com/halo/zjson/JSONUtils.java @@ -0,0 +1,50 @@ +package com.halo.zjson; + +import net.sf.json.JSONObject; +import net.sf.json.JsonConfig; +import net.sf.json.util.JavaIdentifierTransformer; + +import java.util.Map; + +public class JSONUtils { + + private Class clazz; + + public JSONUtils(Class clazz) { + this.clazz = clazz; + } + + @SuppressWarnings("unchecked") + public T getJsonBean(String jsonStr) { + JSONObject jsonObj = JSONObject.fromObject(jsonStr); + return (T) JSONObject.toBean(jsonObj, this.clazz); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public T getComplexJsonBean(String jsonStr, Map classMap) { + JSONObject jsonObj = JSONObject.fromObject(jsonStr); + return (T) JSONObject.toBean(jsonObj, this.clazz, classMap); + } + + public String getJsonStr(T jsonBean) { + JSONObject jsonObj = JSONObject.fromObject(jsonBean); + return jsonObj.toString(); + } + + public T getJsonBeanCaseInsensitive(String jsonStr) { + JsonConfig config = new JsonConfig(); + config.setJavaIdentifierTransformer(new JavaIdentifierTransformer() { + + @Override + public String transformToJavaIdentifier(String str) { + char[] chars = str.toCharArray(); + chars[0] = Character.toLowerCase(chars[0]); + return new String(chars); + } + }); + config.setRootClass(this.clazz); + + JSONObject jsonObj = JSONObject.fromObject(jsonStr); + return (T) JSONObject.toBean(jsonObj, config); + } +} diff --git a/src/test/java/com/halo/AppTest.java b/src/test/java/com/halo/AppTest.java new file mode 100644 index 0000000..50fde81 --- /dev/null +++ b/src/test/java/com/halo/AppTest.java @@ -0,0 +1,20 @@ +package com.halo; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..462c00c --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.6.1 +version=1.7 +groupId=com.halo +artifactId=zjson diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..100e099 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com\halo\zjson\JSONUtils.class +com\halo\zjson\JSONUtils$1.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..b76bbbb --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +D:\idea-workspace\zjson\src\main\java\com\halo\zjson\JSONUtils.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..d4d4e07 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +com\halo\AppTest.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..11c0875 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +D:\idea-workspace\zjson\src\test\java\com\halo\AppTest.java diff --git a/target/surefire-reports/TEST-com.halo.AppTest.xml b/target/surefire-reports/TEST-com.halo.AppTest.xml new file mode 100644 index 0000000..7c57c95 --- /dev/null +++ b/target/surefire-reports/TEST-com.halo.AppTest.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/com.halo.AppTest.txt b/target/surefire-reports/com.halo.AppTest.txt new file mode 100644 index 0000000..b146577 --- /dev/null +++ b/target/surefire-reports/com.halo.AppTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: com.halo.AppTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 s - in com.halo.AppTest diff --git a/zjson.iml b/zjson.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/zjson.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file