-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f8188c3
Showing
11 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.halo</groupId> | ||
<artifactId>zjson</artifactId> | ||
<version>1.7</version> | ||
|
||
<name>zjson</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>nexus-aliyun</id> | ||
<name>nexus-aliyun</name> | ||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url> | ||
<releases> | ||
<enabled>true</enabled> | ||
</releases> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<!-- json-lib dependencies --> | ||
<dependency> | ||
<groupId>net.sf.json-lib</groupId> | ||
<artifactId>json-lib</artifactId> | ||
<version>2.4</version> | ||
<classifier>jdk15</classifier> | ||
</dependency> | ||
<!-- json-lib dependencies --> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
<plugins> | ||
<!-- Build jar package --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<useUniqueVersions>false</useUniqueVersions> | ||
<classpathPrefix>lib/</classpathPrefix> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<!-- Build jar package --> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T> { | ||
|
||
private Class<T> clazz; | ||
|
||
public JSONUtils(Class<T> 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<String, Class> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#Created by Apache Maven 3.6.1 | ||
version=1.7 | ||
groupId=com.halo | ||
artifactId=zjson |
2 changes: 2 additions & 0 deletions
2
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
com\halo\zjson\JSONUtils.class | ||
com\halo\zjson\JSONUtils$1.class |
1 change: 1 addition & 0 deletions
1
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
D:\idea-workspace\zjson\src\main\java\com\halo\zjson\JSONUtils.java |
1 change: 1 addition & 0 deletions
1
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com\halo\AppTest.class |
1 change: 1 addition & 0 deletions
1
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
D:\idea-workspace\zjson\src\test\java\com\halo\AppTest.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="com.halo.AppTest" time="0.031" tests="1" errors="0" skipped="0" failures="0"> | ||
<properties> | ||
<property name="sun.desktop" value="windows"/> | ||
<property name="awt.toolkit" value="sun.awt.windows.WToolkit"/> | ||
<property name="file.encoding.pkg" value="sun.io"/> | ||
<property name="java.specification.version" value="1.8"/> | ||
<property name="sun.cpu.isalist" value="amd64"/> | ||
<property name="sun.jnu.encoding" value="GBK"/> | ||
<property name="java.class.path" value="D:\idea-workspace\zjson\target\test-classes;D:\idea-workspace\zjson\target\classes;C:\Users\13971\.m2\repository\net\sf\json-lib\json-lib\2.4\json-lib-2.4-jdk15.jar;C:\Users\13971\.m2\repository\commons-beanutils\commons-beanutils\1.8.0\commons-beanutils-1.8.0.jar;C:\Users\13971\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\13971\.m2\repository\commons-lang\commons-lang\2.5\commons-lang-2.5.jar;C:\Users\13971\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;C:\Users\13971\.m2\repository\net\sf\ezmorph\ezmorph\1.0.6\ezmorph-1.0.6.jar;C:\Users\13971\.m2\repository\junit\junit\4.11\junit-4.11.jar;C:\Users\13971\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;"/> | ||
<property name="java.vm.vendor" value="Oracle Corporation"/> | ||
<property name="sun.arch.data.model" value="64"/> | ||
<property name="user.variant" value=""/> | ||
<property name="java.vendor.url" value="http://java.oracle.com/"/> | ||
<property name="user.timezone" value="Asia/Shanghai"/> | ||
<property name="java.vm.specification.version" value="1.8"/> | ||
<property name="os.name" value="Windows 10"/> | ||
<property name="user.country" value="CN"/> | ||
<property name="sun.java.launcher" value="SUN_STANDARD"/> | ||
<property name="sun.boot.library.path" value="D:\Java\jdk1.8.0_231\jre\bin"/> | ||
<property name="sun.java.command" value="C:\Users\13971\AppData\Local\Temp\surefire2180405355800475329\surefirebooter1740418544571641392.jar C:\Users\13971\AppData\Local\Temp\surefire2180405355800475329 2021-04-01T16-22-49_613-jvmRun1 surefire2281344131939374140tmp surefire_09089619934187464389tmp"/> | ||
<property name="surefire.test.class.path" value="D:\idea-workspace\zjson\target\test-classes;D:\idea-workspace\zjson\target\classes;C:\Users\13971\.m2\repository\net\sf\json-lib\json-lib\2.4\json-lib-2.4-jdk15.jar;C:\Users\13971\.m2\repository\commons-beanutils\commons-beanutils\1.8.0\commons-beanutils-1.8.0.jar;C:\Users\13971\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\13971\.m2\repository\commons-lang\commons-lang\2.5\commons-lang-2.5.jar;C:\Users\13971\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;C:\Users\13971\.m2\repository\net\sf\ezmorph\ezmorph\1.0.6\ezmorph-1.0.6.jar;C:\Users\13971\.m2\repository\junit\junit\4.11\junit-4.11.jar;C:\Users\13971\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;"/> | ||
<property name="sun.cpu.endian" value="little"/> | ||
<property name="user.home" value="C:\Users\13971"/> | ||
<property name="user.language" value="zh"/> | ||
<property name="java.specification.vendor" value="Oracle Corporation"/> | ||
<property name="java.home" value="D:\Java\jdk1.8.0_231\jre"/> | ||
<property name="basedir" value="D:\idea-workspace\zjson"/> | ||
<property name="file.separator" value="\"/> | ||
<property name="line.separator" value=" "/> | ||
<property name="java.vm.specification.vendor" value="Oracle Corporation"/> | ||
<property name="java.specification.name" value="Java Platform API Specification"/> | ||
<property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/> | ||
<property name="surefire.real.class.path" value="C:\Users\13971\AppData\Local\Temp\surefire2180405355800475329\surefirebooter1740418544571641392.jar"/> | ||
<property name="sun.boot.class.path" value="D:\Java\jdk1.8.0_231\jre\lib\resources.jar;D:\Java\jdk1.8.0_231\jre\lib\rt.jar;D:\Java\jdk1.8.0_231\jre\lib\sunrsasign.jar;D:\Java\jdk1.8.0_231\jre\lib\jsse.jar;D:\Java\jdk1.8.0_231\jre\lib\jce.jar;D:\Java\jdk1.8.0_231\jre\lib\charsets.jar;D:\Java\jdk1.8.0_231\jre\lib\jfr.jar;D:\Java\jdk1.8.0_231\jre\classes"/> | ||
<property name="user.script" value=""/> | ||
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/> | ||
<property name="java.runtime.version" value="1.8.0_231-b11"/> | ||
<property name="user.name" value="13971"/> | ||
<property name="path.separator" value=";"/> | ||
<property name="os.version" value="10.0"/> | ||
<property name="java.endorsed.dirs" value="D:\Java\jdk1.8.0_231\jre\lib\endorsed"/> | ||
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/> | ||
<property name="file.encoding" value="GBK"/> | ||
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/> | ||
<property name="localRepository" value="C:\Users\13971\.m2\repository"/> | ||
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/> | ||
<property name="java.io.tmpdir" value="C:\Users\13971\AppData\Local\Temp\"/> | ||
<property name="java.version" value="1.8.0_231"/> | ||
<property name="user.dir" value="D:\idea-workspace\zjson"/> | ||
<property name="os.arch" value="amd64"/> | ||
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/> | ||
<property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/> | ||
<property name="sun.os.patch.level" value=""/> | ||
<property name="java.library.path" value="D:\Java\jdk1.8.0_231\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;D:\Java\jdk1.8.0_231\bin;D:\tomcat8.5\bin;D:\apache-maven-3.6.2\bin\;D:\Program Files\Git\cmd;C:\Users\13971\AppData\Local\Microsoft\WindowsApps;;."/> | ||
<property name="java.vm.info" value="mixed mode"/> | ||
<property name="java.vendor" value="Oracle Corporation"/> | ||
<property name="java.vm.version" value="25.231-b11"/> | ||
<property name="idea.version2019.3" value="true"/> | ||
<property name="java.ext.dirs" value="D:\Java\jdk1.8.0_231\jre\lib\ext;C:\Windows\Sun\Java\lib\ext"/> | ||
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/> | ||
<property name="java.class.version" value="52.0"/> | ||
</properties> | ||
<testcase name="shouldAnswerWithTrue" classname="com.halo.AppTest" time="0"/> | ||
</testsuite> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4" /> |