Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial import struts2 plugin

  • Loading branch information...
commit 5d50dff7ccdd42cdb038a6a0151c660c680daf56 1 parent b2837d7
@grobmeier authored
Showing with 2,123 additions and 1,596 deletions.
  1. +0 −7 .classpath
  2. +0 −13 .project
  3. +20 −0 jjson-struts2/.classpath
  4. +15 −0 jjson-struts2/.project
  5. +9 −0 jjson-struts2/.settings/org.eclipse.jdt.core.prefs
  6. +202 −0 jjson-struts2/LICENSE.txt
  7. +5 −0 jjson-struts2/NOTICE.txt
  8. +84 −0 jjson-struts2/pom.xml
  9. +138 −0 jjson-struts2/src/main/java/de/grobmeier/json/plugins/struts2/JsonResult.java
  10. +13 −0 jjson-struts2/src/main/resources/struts-plugin.xml
  11. +10 −2 jjson/pom.xml
  12. +74 −74 jjson/src/main/java/de/grobmeier/jjson/JSONArray.java
  13. +45 −45 jjson/src/main/java/de/grobmeier/jjson/JSONBoolean.java
  14. +39 −39 jjson/src/main/java/de/grobmeier/jjson/JSONNull.java
  15. +79 −79 jjson/src/main/java/de/grobmeier/jjson/JSONNumber.java
  16. +70 −70 jjson/src/main/java/de/grobmeier/jjson/JSONObject.java
  17. +64 −64 jjson/src/main/java/de/grobmeier/jjson/JSONString.java
  18. +27 −27 jjson/src/main/java/de/grobmeier/jjson/JSONValue.java
  19. +298 −298 jjson/src/main/java/de/grobmeier/jjson/convert/JSONAnnotationEncoder.java
  20. +402 −402 jjson/src/main/java/de/grobmeier/jjson/convert/JSONDecoder.java
  21. +43 −43 jjson/src/test/java/de/grobmeier/jjson/JSONArrayTest.java
  22. +66 −66 jjson/src/test/java/de/grobmeier/jjson/JSONObjectTest.java
  23. +120 −120 jjson/src/test/java/de/grobmeier/jjson/convert/AnnotatedTestClass.java
  24. +40 −40 jjson/src/test/java/de/grobmeier/jjson/convert/JSONAnnotationEncoderTest.java
  25. +207 −207 jjson/src/test/java/de/grobmeier/jjson/convert/JSONDecoderTest.java
  26. +53 −0 pom.xml
View
7 .classpath
@@ -1,7 +0,0 @@
-<classpath>
- <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
- <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
- <classpathentry kind="output" path="target/classes"/>
- <classpathentry kind="var" path="M2_REPO/junit/junit/4.4/junit-4.4.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
-</classpath>
View
13 .project
@@ -1,13 +0,0 @@
-<projectDescription>
- <name>jjson</name>
- <comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
- <projects/>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
View
20 jjson-struts2/.classpath
@@ -0,0 +1,20 @@
+<classpath>
+ <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
+ <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+ <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="var" path="M2_REPO/javax/servlet/jsp-api/2.0/jsp-api-2.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-fileupload/commons-fileupload/1.2.1/commons-fileupload-1.2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/freemarker/freemarker/2.3.15/freemarker-2.3.15.jar"/>
+ <classpathentry kind="var" path="M2_REPO/jboss/javassist/3.7.ga/javassist-3.7.ga.jar"/>
+ <classpathentry kind="src" path="/jjson"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/4.8.1/junit-4.8.1.jar" sourcepath="M2_REPO/junit/junit/4.8.1/junit-4.8.1-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/ognl/ognl/2.7.3/ognl-2.7.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/springframework/spring-test/2.5.6/spring-test-2.5.6.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/struts/struts2-core/2.1.8.1/struts2-core-2.1.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/com/opensymphony/xwork-core/2.1.6/xwork-core-2.1.6.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+</classpath>
View
15 jjson-struts2/.project
@@ -0,0 +1,15 @@
+<projectDescription>
+ <name>jjson-struts2</name>
+ <comment>JJSON is consisting of API and framework plugins for dealing with the JSON specification. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
+ <projects>
+ <project>jjson</project>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
9 jjson-struts2/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,9 @@
+#Fri Jul 01 12:16:46 CEST 2011
+encoding//src/test/java=UTF-8
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+encoding//src/test/resources=UTF-8
+org.eclipse.jdt.core.compiler.source=1.5
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+org.eclipse.jdt.core.compiler.compliance=1.5
View
202 jjson-struts2/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
View
5 jjson-struts2/NOTICE.txt
@@ -0,0 +1,5 @@
+JJSON - Struts 2 plugin
+Copyright 2002-2009 Christian Grobmeier
+
+This product includes software developed by
+Christian Grobmeier(http://www.grobmeier.de/).
View
84 jjson-struts2/pom.xml
@@ -0,0 +1,84 @@
+<?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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>parent</artifactId>
+ <groupId>de.grobmeier.json</groupId>
+ <version>0.0.0-SNAPSHOT</version>
+ </parent>
+ <groupId>de.grobmeier.json</groupId>
+ <artifactId>jjson-struts2</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>jjson-struts2</name>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <struts2.version>2.1.8.1</struts2.version>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <encoding>UTF-8</encoding>
+ <compilerArgument />
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.1</version>
+ </plugin>
+
+ <!-- surefire -->
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.9</version>
+ <configuration>
+ <encoding>UTF-8</encoding>
+ <argLine>'-Dfile.encoding=UTF-8'</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>de.grobmeier.json</groupId>
+ <artifactId>jjson</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ </dependency>
+ <!-- Struts 2 -->
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-core</artifactId>
+ <version>${struts2.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.opensymphony</groupId>
+ <artifactId>xwork-core</artifactId>
+ <version>2.1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
View
138 jjson-struts2/src/main/java/de/grobmeier/json/plugins/struts2/JsonResult.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.json.plugins.struts2;
+
+import java.io.PrintWriter;
+import java.nio.charset.Charset;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts2.dispatcher.StrutsResultSupport;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionSupport;
+
+import de.grobmeier.jjson.convert.JSONAnnotationEncoder;
+
+/**
+ *
+ * @author grobmeier
+ */
+public class JsonResult extends StrutsResultSupport {
+ /** Serial */
+ private static final long serialVersionUID = 2476992951577523951L;
+
+ /** Log */
+ private static final Log log = LogFactory.getLog(JsonResult.class);
+
+ private String charSet = "UTF-8";
+
+ /** Default constructor */
+ public JsonResult() {
+ }
+
+ /**
+ * @param location
+ */
+ public JsonResult(String location) {
+ super(location);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.apache.struts2.dispatcher.StrutsResultSupport#doExecute(java.lang
+ * .String, com.opensymphony.xwork2.ActionInvocation)
+ */
+ @Override
+ protected void doExecute(String finalLocation, ActionInvocation invocation)
+ throws Exception {
+ Charset charset = null;
+ if (charSet != null) {
+ if (Charset.isSupported(charSet)) {
+ charset = Charset.forName(charSet);
+ } else {
+ charset = null;
+ }
+ }
+
+ HttpServletResponse response = (HttpServletResponse) invocation
+ .getInvocationContext().get(HTTP_RESPONSE);
+
+ if (charset != null) {
+ response.setContentType("application/json; charset=UTF-8");
+ } else {
+ response.setContentType("application/json");
+ }
+ response.setHeader("Content-Disposition", "inline");
+
+ // allows crosssite ajax - TODO: should be optional
+ response.setHeader("Access-Control-Allow-Origin", "*");
+ response.setHeader("Access-Control-Allow-Methods", "POST,GET");
+ response.setHeader("Access-Control-Allow-Credentials", "true");
+
+ PrintWriter writer = response.getWriter();
+ try {
+ if (!ActionSupport.SUCCESS.equals(invocation.getResultCode())) {
+ if(ActionSupport.LOGIN.equals(invocation.getResultCode())) {
+ response.sendError(401, "Not authorized");
+ return;
+ } else if("forbidden".equalsIgnoreCase(invocation.getResultCode())) {
+ response.sendError(403, "Request is not allowed");
+ return;
+ } else if(ActionSupport.ERROR.equalsIgnoreCase(invocation.getResultCode())) {
+ response.sendError(500, "Server error");
+ return;
+ }
+
+ writer.write(new char[] { 'n', 'u', 'l', 'l' }, 0, 4);
+ return;
+ }
+ Object obj = invocation.getAction();
+ JSONAnnotationEncoder encoder = new JSONAnnotationEncoder();
+ String result = encoder.encode(obj);
+ log.debug("Encoded JSON: " + result);
+ writer.write(result);
+ } finally {
+ if (writer != null) {
+ writer.flush();
+ writer.close();
+ }
+ }
+ }
+
+ /**
+ * Set the character set
+ *
+ * @return The character set
+ */
+ public String getCharSet() {
+ return charSet;
+ }
+
+ /**
+ * Set the character set
+ *
+ * @param charSet
+ * The character set
+ */
+ public void setCharSet(String charSet) {
+ this.charSet = charSet;
+ }
+}
View
13 jjson-struts2/src/main/resources/struts-plugin.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
+ "http://struts.apache.org/dtds/struts-2.1.7.dtd">
+
+<struts>
+ <package name="json-default" extends="struts-default">
+ <result-types>
+ <result-type name="json" class="de.grobmeier.tab.plugins.json.JsonResult"/>
+ </result-types>
+ </package>
+</struts>
View
12 jjson/pom.xml
@@ -18,12 +18,17 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>de.grobmeier</groupId>
+ <parent>
+ <artifactId>parent</artifactId>
+ <groupId>de.grobmeier.json</groupId>
+ <version>0.0.0-SNAPSHOT</version>
+ </parent>
+ <groupId>de.grobmeier.json</groupId>
<artifactId>jjson</artifactId>
<packaging>jar</packaging>
<version>0.1.0-SNAPSHOT</version>
<name>jjson</name>
- <url>http://maven.apache.org</url>
+ <url>http://code.google.com/p/jjson</url>
<developers>
<developer>
<id>grobmeier</id>
@@ -47,6 +52,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
@@ -58,11 +64,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.1</version>
</plugin>
<!-- surefire -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
+ <version>2.9</version>
<configuration>
<encoding>UTF-8</encoding>
<argLine>'-Dfile.encoding=UTF-8'</argLine>
View
148 jjson/src/main/java/de/grobmeier/jjson/JSONArray.java
@@ -1,74 +1,74 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- *
- */
-public class JSONArray implements JSONValue {
- private List<JSONValue> values = new ArrayList<JSONValue>();
- /**
- *
- */
- public JSONArray() {
- }
-
- public void add(JSONValue value) {
- if(value == null) {
- value = JSONNull.NULL;
- }
- values.add(value);
- }
-
- /**
- * @return the values
- */
- public List<JSONValue> getValue() {
- return values;
- }
-
- /**
- * @param values the values to set
- */
- public void setValues(List<JSONValue> values) {
- this.values = values;
- }
-
- /**
- * (non-Javadoc)
- * @see org.apache.commons.json.JSONValue#toJSON()
- */
- public String toJSON() {
- StringBuffer result = new StringBuffer();
- result.append("[");
-
- Iterator<JSONValue> it = values.iterator();
- while(it.hasNext()) {
- JSONValue value = (JSONValue)it.next();
- result.append(value.toJSON());
- if(it.hasNext()) {
- result.append(",");
- }
- }
- result.append("]");
- return result.toString();
- }
-
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ *
+ */
+public class JSONArray implements JSONValue {
+ private List<JSONValue> values = new ArrayList<JSONValue>();
+ /**
+ *
+ */
+ public JSONArray() {
+ }
+
+ public void add(JSONValue value) {
+ if(value == null) {
+ value = JSONNull.NULL;
+ }
+ values.add(value);
+ }
+
+ /**
+ * @return the values
+ */
+ public List<JSONValue> getValue() {
+ return values;
+ }
+
+ /**
+ * @param values the values to set
+ */
+ public void setValues(List<JSONValue> values) {
+ this.values = values;
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see org.apache.commons.json.JSONValue#toJSON()
+ */
+ public String toJSON() {
+ StringBuffer result = new StringBuffer();
+ result.append("[");
+
+ Iterator<JSONValue> it = values.iterator();
+ while(it.hasNext()) {
+ JSONValue value = (JSONValue)it.next();
+ result.append(value.toJSON());
+ if(it.hasNext()) {
+ result.append(",");
+ }
+ }
+ result.append("]");
+ return result.toString();
+ }
+
+}
View
90 jjson/src/main/java/de/grobmeier/jjson/JSONBoolean.java
@@ -1,45 +1,45 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson;
-
-public class JSONBoolean implements JSONValue {
- /** JSONBoolean Object with the value true */
- public final static JSONBoolean TRUE = new JSONBoolean(true);
- /** JSONBoolean Object with the value false */
- public final static JSONBoolean FALSE = new JSONBoolean(true);
-
- /* value of this object */
- private boolean value = false;
-
- /**
- * @return the value
- */
- public boolean getValue() {
- return value;
- }
-
- /**
- * @param value
- */
- public JSONBoolean(boolean value) {
- this.value = value;
- }
-
- public String toJSON() {
- return Boolean.toString(value);
- }
-
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson;
+
+public class JSONBoolean implements JSONValue {
+ /** JSONBoolean Object with the value true */
+ public final static JSONBoolean TRUE = new JSONBoolean(true);
+ /** JSONBoolean Object with the value false */
+ public final static JSONBoolean FALSE = new JSONBoolean(true);
+
+ /* value of this object */
+ private boolean value = false;
+
+ /**
+ * @return the value
+ */
+ public boolean getValue() {
+ return value;
+ }
+
+ /**
+ * @param value
+ */
+ public JSONBoolean(boolean value) {
+ this.value = value;
+ }
+
+ public String toJSON() {
+ return Boolean.toString(value);
+ }
+
+}
View
78 jjson/src/main/java/de/grobmeier/jjson/JSONNull.java
@@ -1,39 +1,39 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson;
-
-/**
- *
- */
-public class JSONNull implements JSONValue {
-
- public static final JSONNull NULL = new JSONNull();
-
- /**
- *
- */
- public JSONNull() {
- // no values
- }
-
- /**
- * (non-Javadoc)
- * @see org.apache.commons.json.JSONValue#toJSON()
- */
- public String toJSON() {
- return "null";
- }
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson;
+
+/**
+ *
+ */
+public class JSONNull implements JSONValue {
+
+ public static final JSONNull NULL = new JSONNull();
+
+ /**
+ *
+ */
+ public JSONNull() {
+ // no values
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see org.apache.commons.json.JSONValue#toJSON()
+ */
+ public String toJSON() {
+ return "null";
+ }
+}
View
158 jjson/src/main/java/de/grobmeier/jjson/JSONNumber.java
@@ -1,79 +1,79 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson;
-
-
-import java.math.BigDecimal;
-
-
-public class JSONNumber implements JSONValue {
- private String value = "0";
- /**
- *
- */
- public JSONNumber(double value) {
- this.value = Double.toString(value);
- }
-
- /**
- * @param value
- */
- public JSONNumber(String value) {
- this.value = value;
- }
-
- /**
- * @param value
- */
- public JSONNumber(long value) {
- this.value = Long.toString(value);
- }
-
- /**
- * @param value
- */
- public JSONNumber(float value) {
- this.value = Float.toString(value);
- }
-
- /**
- * @param value
- */
- public JSONNumber(BigDecimal value) {
- this.value = value.toPlainString();
- }
-
- public JSONNumber(int value) {
- this.value = Integer.toString(value);
- }
-
-
- /**
- * @return the value
- */
- public String getValue() {
- return value;
- }
-
- /**
- * (non-Javadoc)
- * @see org.apache.commons.json.JSONValue#toJSON()
- */
- public String toJSON() {
- return value;
- }
-
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson;
+
+
+import java.math.BigDecimal;
+
+
+public class JSONNumber implements JSONValue {
+ private String value = "0";
+ /**
+ *
+ */
+ public JSONNumber(double value) {
+ this.value = Double.toString(value);
+ }
+
+ /**
+ * @param value
+ */
+ public JSONNumber(String value) {
+ this.value = value;
+ }
+
+ /**
+ * @param value
+ */
+ public JSONNumber(long value) {
+ this.value = Long.toString(value);
+ }
+
+ /**
+ * @param value
+ */
+ public JSONNumber(float value) {
+ this.value = Float.toString(value);
+ }
+
+ /**
+ * @param value
+ */
+ public JSONNumber(BigDecimal value) {
+ this.value = value.toPlainString();
+ }
+
+ public JSONNumber(int value) {
+ this.value = Integer.toString(value);
+ }
+
+
+ /**
+ * @return the value
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see org.apache.commons.json.JSONValue#toJSON()
+ */
+ public String toJSON() {
+ return value;
+ }
+
+}
View
140 jjson/src/main/java/de/grobmeier/jjson/JSONObject.java
@@ -1,70 +1,70 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-
-
-public class JSONObject implements JSONValue {
- private Map<String, JSONValue> object = new HashMap<String, JSONValue>();
-
- /**
- *
- */
- public JSONObject() {
- }
-
- /**
- * @param key
- * @param value
- */
- public void put(final String key, JSONValue value) {
- if(value == null) {
- value = JSONNull.NULL;
- }
- object.put(key, value);
- }
-
- /**
- * @return the object
- */
- public Map<String, JSONValue> getValue() {
- return object;
- }
-
- public String toJSON() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("{");
- Set<String> keys = object.keySet();
- Iterator<String> it = keys.iterator();
- while(it.hasNext()) {
- String key = (String)it.next();
- buffer.append("\"");
- buffer.append(key);
- buffer.append("\":");
- buffer.append(object.get(key).toJSON());
- if(it.hasNext()) {
- buffer.append(",");
- }
- }
- buffer.append("}");
- return buffer.toString();
- }
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+
+
+public class JSONObject implements JSONValue {
+ private Map<String, JSONValue> object = new HashMap<String, JSONValue>();
+
+ /**
+ *
+ */
+ public JSONObject() {
+ }
+
+ /**
+ * @param key
+ * @param value
+ */
+ public void put(final String key, JSONValue value) {
+ if(value == null) {
+ value = JSONNull.NULL;
+ }
+ object.put(key, value);
+ }
+
+ /**
+ * @return the object
+ */
+ public Map<String, JSONValue> getValue() {
+ return object;
+ }
+
+ public String toJSON() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("{");
+ Set<String> keys = object.keySet();
+ Iterator<String> it = keys.iterator();
+ while(it.hasNext()) {
+ String key = (String)it.next();
+ buffer.append("\"");
+ buffer.append(key);
+ buffer.append("\":");
+ buffer.append(object.get(key).toJSON());
+ if(it.hasNext()) {
+ buffer.append(",");
+ }
+ }
+ buffer.append("}");
+ return buffer.toString();
+ }
+}
View
128 jjson/src/main/java/de/grobmeier/jjson/JSONString.java
@@ -1,64 +1,64 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson;
-
-
-
-public class JSONString implements JSONValue {
- private StringBuffer buffer = new StringBuffer();
-
- /**
- * @param value
- */
- public JSONString(final String value) {
- buffer.append(value);
- }
-
- /**
- * @param append
- */
- public void append(final String append) {
- buffer.append(append);
- }
-
- /**
- * @return the buffer
- */
- public StringBuffer getValue() {
- return buffer;
- }
-
- /**
- * (non-Javadoc)
- * @see org.apache.commons.json.JSONValue#toJSON()
- */
- public String toJSON() {
- StringBuffer result = new StringBuffer();
- result.append("\"");
- result.append(buffer);
- result.append("\"");
- return result.toString();
- }
-
- /**
- * (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return buffer.toString();
- }
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson;
+
+
+
+public class JSONString implements JSONValue {
+ private StringBuffer buffer = new StringBuffer();
+
+ /**
+ * @param value
+ */
+ public JSONString(final String value) {
+ buffer.append(value);
+ }
+
+ /**
+ * @param append
+ */
+ public void append(final String append) {
+ buffer.append(append);
+ }
+
+ /**
+ * @return the buffer
+ */
+ public StringBuffer getValue() {
+ return buffer;
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see org.apache.commons.json.JSONValue#toJSON()
+ */
+ public String toJSON() {
+ StringBuffer result = new StringBuffer();
+ result.append("\"");
+ result.append(buffer);
+ result.append("\"");
+ return result.toString();
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return buffer.toString();
+ }
+}
View
54 jjson/src/main/java/de/grobmeier/jjson/JSONValue.java
@@ -1,27 +1,27 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson;
-
-/**
- *
- */
-public interface JSONValue {
- /**
- * Generates the JSON-String for this value object.
- * @return the JSON-String
- */
- public String toJSON();
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson;
+
+/**
+ *
+ */
+public interface JSONValue {
+ /**
+ * Generates the JSON-String for this value object.
+ * @return the JSON-String
+ */
+ public String toJSON();
+}
View
596 jjson/src/main/java/de/grobmeier/jjson/convert/JSONAnnotationEncoder.java
@@ -1,298 +1,298 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson.convert;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import de.grobmeier.jjson.JSONException;
-
-/**
- *
- */
-public class JSONAnnotationEncoder {
- // Key signs
- // TODO: use allready defined Openener/Closer Enums from basic decoder
- private static final String QUOTE = "\"";
- private static final String PRIMITIVE_BOOLEAN = "boolean";
- private static final String ARRAY_RIGHT = "]";
- private static final String ARRAY_LEFT = "[";
- private static final String BRACKET_RIGHT = "}";
- private static final String COLON = ":";
- private static final String COMMA = ",";
- private static final String EMTPY_STRING = "";
- private static final String BRACKET_LEFT = "{";
-
- /** Default format for dates */
- private final static SimpleDateFormat DEFAULT_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
-
- private Map<String, SimpleDateFormat> formatterPool = new HashMap<String, SimpleDateFormat>();
-
- // Special values
- private final static String NULL = "null";
-
- public String encode(Object result) throws JSONException {
- StringBuilder builder = new StringBuilder();
- encode(result, builder, null);
- return builder.toString();
- }
-
- /**
- * @param builder
- * @param result
- * @throws JSONException
- */
- @SuppressWarnings("unchecked")
- public void encode(Object result, StringBuilder builder, JSON annotation) throws JSONException {
- if(result == null) {
- builder.append(NULL);
- } else if(result.getClass().isAssignableFrom(String.class)) {
- encodeString(((String)result), builder);
- } else if(result.getClass().isAssignableFrom(Integer.class)) {
- encodeInteger((Integer)result, builder);
- } else if(result.getClass().isAssignableFrom(Boolean.class)) {
- encodeBoolean((Boolean)result, builder);
- } else if(hasInterface(result, List.class)) {
- encodeList((List<Object>)result, builder);
- } else if(hasInterface(result, Map.class)) {
- encodeMap((Map<Object, Object>)result, builder);
- } else if(result.getClass().isAssignableFrom(Date.class)) {
- encodeDate((Date)result, builder, annotation);
- } else if(result.getClass().isArray()) {
- encodeArray(result, builder);
- } else {
- encodeObject(result, builder);
- }
- }
-
- private void encodeArray(Object result, StringBuilder builder) throws JSONException {
- builder.append(ARRAY_LEFT);
- int length = Array.getLength(result);
- for (int i = 0; i < length; i++) {
- if(i > 0) {
- builder.append(COMMA);
- }
- encode(Array.get(result, i), builder, null);
- }
- builder.append(ARRAY_RIGHT);
- }
-
- private void encodeDate(Date result, StringBuilder builder, JSON annotation) throws JSONException {
- String customFormat = annotation.dateFormat();
- if(customFormat != null && !"".equals(customFormat)) {
- SimpleDateFormat format = formatterPool.get(customFormat);
- if(format == null) {
- format = new SimpleDateFormat(customFormat);
- formatterPool.put(customFormat, format);
- }
- encodeString(format.format(result), builder);
- } else {
- encodeString(DEFAULT_FORMAT.format(result), builder);
- }
-
- }
-
- private void encodeMap(Map<Object, Object> result, StringBuilder builder) throws JSONException {
- boolean first = true;
- builder.append(BRACKET_LEFT);
- Set<Entry<Object, Object>> entries = result.entrySet();
- for (Iterator<Entry<Object, Object>> iterator = entries.iterator(); iterator.hasNext();) {
- if(!first) {
- builder.append(COMMA);
- } else {
- first = false;
- }
- Entry<Object, Object> entry = (Entry<Object, Object>) iterator.next();
- encodeString(entry.getKey().toString(), builder);
- builder.append(COLON);
- encode(entry.getValue(), builder,null);
- }
- builder.append(BRACKET_RIGHT);
- }
-
- private void encodeList(List<Object> result, StringBuilder builder) throws JSONException {
- boolean first = true;
- builder.append(ARRAY_LEFT);
- for (Iterator<Object> iterator = result.iterator(); iterator.hasNext();) {
- if(!first) {
- builder.append(COMMA);
- } else {
- first = false;
- }
-
- Object object = iterator.next();
- encode(object, builder, null);
- }
- builder.append(ARRAY_RIGHT);
- }
-
- private String encodeObject(Object c, StringBuilder builder) throws JSONException {
- if(c == null) {
- return NULL;
- }
-
- if(c.getClass().getAnnotation(JSON.class) == null) {
- return null;
- }
-
- builder.append(BRACKET_LEFT);
-
- serializeFields(c, builder);
- serializeMethods(c, builder);
- builder.append(BRACKET_RIGHT);
- return builder.toString();
- }
-
- private void serializeFields(Object c, StringBuilder builder)
- throws JSONException {
- boolean first = true;
- Field[] fields = c.getClass().getDeclaredFields();
- for (Field field : fields) {
- Annotation[] anons = field.getAnnotations();
- for (Annotation annotation : anons) {
- if(annotation.annotationType().isAssignableFrom(JSON.class)) {
- if(!first) {
- builder.append(COMMA);
- } else {
- first = false;
- }
-
- String methodName = null;
- // primitive boolean getters have is as prefix
- // Use class.getComponentType instead of this
- if(PRIMITIVE_BOOLEAN.equals(field.getType().toString())) {
- methodName = JSONReflectionUtils.createGetter(field.getName(), JSONReflectionUtils.IS);
- } else {
- methodName = JSONReflectionUtils.createGetter(field.getName(), JSONReflectionUtils.GET);
- }
-
- try {
- Method method = c.getClass().getMethod(methodName, (Class[])null);
- Object result = method.invoke(c, (Object[])null);
-
- encodeString(field.getName(), builder);
- builder.append(COLON);
- encode(result, builder,(JSON)annotation);
- } catch (SecurityException e) {
- throw new JSONException(e);
- } catch (NoSuchMethodException e) {
- throw new JSONException("No appropriate getter found: " + methodName ,e);
- } catch (IllegalArgumentException e) {
- throw new JSONException(e);
- } catch (IllegalAccessException e) {
- throw new JSONException(e);
- } catch (InvocationTargetException e) {
- throw new JSONException(e);
- }
- }
- }
- }
- }
-
- private void serializeMethods(Object c, StringBuilder builder) throws JSONException {
- boolean first = true;
- Method[] methods = c.getClass().getDeclaredMethods();
- for (Method method : methods) {
- Annotation[] anons = method.getAnnotations();
- for (Annotation annotation : anons) {
- if(annotation.annotationType().isAssignableFrom(JSON.class)) {
- if(!first) {
- builder.append(COMMA);
- } else {
- first = false;
- }
-
- try {
- Object result = method.invoke(c, (Object[])null);
- String name = method.getName();
- if(name.startsWith("is")) {
- name = name.replaceFirst("is", "");
- name = name.substring(0, 1).toLowerCase() + name.substring(1);
- }
- if(name.startsWith("get")) {
- name = name.replaceFirst("get", "");
- name = name.substring(0, 1).toLowerCase() + name.substring(1);
- }
- encodeString(name, builder);
- builder.append(COLON);
- encode(result, builder, (JSON)annotation);
- } catch (SecurityException e) {
- throw new JSONException(e);
- } catch (IllegalArgumentException e) {
- throw new JSONException(e);
- } catch (IllegalAccessException e) {
- throw new JSONException(e);
- } catch (InvocationTargetException e) {
- throw new JSONException(e);
- }
- }
- }
- }
- }
-
- private void encodeString(String string, StringBuilder result) {
- if(string == null) {
- result.append(NULL);
- } else {
- result.append(QUOTE);
- result.append(string);
- result.append(QUOTE);
- }
- }
-
- private void encodeInteger(Integer integer, StringBuilder result) {
- if(integer == null) {
- result.append(NULL);
- } else {
- result.append(EMTPY_STRING);
- result.append(integer);
- result.append(EMTPY_STRING);
- }
- }
-
- private void encodeBoolean(Boolean b, StringBuilder result) {
- if(b == null) {
- result.append(NULL);
- } else {
- result.append(EMTPY_STRING);
- result.append(Boolean.toString(b));
- result.append(EMTPY_STRING);
- }
- }
-
- private boolean hasInterface(Object target, Class<?> interfaceClass) {
- Class<?>[] interfaces = target.getClass().getInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- if(interfaceClass.getName().equals(interfaces[i].getName())) {
- return true;
- }
- }
- return false;
- }
-
-
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson.convert;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import de.grobmeier.jjson.JSONException;
+
+/**
+ *
+ */
+public class JSONAnnotationEncoder {
+ // Key signs
+ // TODO: use allready defined Openener/Closer Enums from basic decoder
+ private static final String QUOTE = "\"";
+ private static final String PRIMITIVE_BOOLEAN = "boolean";
+ private static final String ARRAY_RIGHT = "]";
+ private static final String ARRAY_LEFT = "[";
+ private static final String BRACKET_RIGHT = "}";
+ private static final String COLON = ":";
+ private static final String COMMA = ",";
+ private static final String EMTPY_STRING = "";
+ private static final String BRACKET_LEFT = "{";
+
+ /** Default format for dates */
+ private final static SimpleDateFormat DEFAULT_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
+
+ private Map<String, SimpleDateFormat> formatterPool = new HashMap<String, SimpleDateFormat>();
+
+ // Special values
+ private final static String NULL = "null";
+
+ public String encode(Object result) throws JSONException {
+ StringBuilder builder = new StringBuilder();
+ encode(result, builder, null);
+ return builder.toString();
+ }
+
+ /**
+ * @param builder
+ * @param result
+ * @throws JSONException
+ */
+ @SuppressWarnings("unchecked")
+ public void encode(Object result, StringBuilder builder, JSON annotation) throws JSONException {
+ if(result == null) {
+ builder.append(NULL);
+ } else if(result.getClass().isAssignableFrom(String.class)) {
+ encodeString(((String)result), builder);
+ } else if(result.getClass().isAssignableFrom(Integer.class)) {
+ encodeInteger((Integer)result, builder);
+ } else if(result.getClass().isAssignableFrom(Boolean.class)) {
+ encodeBoolean((Boolean)result, builder);
+ } else if(hasInterface(result, List.class)) {
+ encodeList((List<Object>)result, builder);
+ } else if(hasInterface(result, Map.class)) {
+ encodeMap((Map<Object, Object>)result, builder);
+ } else if(result.getClass().isAssignableFrom(Date.class)) {
+ encodeDate((Date)result, builder, annotation);
+ } else if(result.getClass().isArray()) {
+ encodeArray(result, builder);
+ } else {
+ encodeObject(result, builder);
+ }
+ }
+
+ private void encodeArray(Object result, StringBuilder builder) throws JSONException {
+ builder.append(ARRAY_LEFT);
+ int length = Array.getLength(result);
+ for (int i = 0; i < length; i++) {
+ if(i > 0) {
+ builder.append(COMMA);
+ }
+ encode(Array.get(result, i), builder, null);
+ }
+ builder.append(ARRAY_RIGHT);
+ }
+
+ private void encodeDate(Date result, StringBuilder builder, JSON annotation) throws JSONException {
+ String customFormat = annotation.dateFormat();
+ if(customFormat != null && !"".equals(customFormat)) {
+ SimpleDateFormat format = formatterPool.get(customFormat);
+ if(format == null) {
+ format = new SimpleDateFormat(customFormat);
+ formatterPool.put(customFormat, format);
+ }
+ encodeString(format.format(result), builder);
+ } else {
+ encodeString(DEFAULT_FORMAT.format(result), builder);
+ }
+
+ }
+
+ private void encodeMap(Map<Object, Object> result, StringBuilder builder) throws JSONException {
+ boolean first = true;
+ builder.append(BRACKET_LEFT);
+ Set<Entry<Object, Object>> entries = result.entrySet();
+ for (Iterator<Entry<Object, Object>> iterator = entries.iterator(); iterator.hasNext();) {
+ if(!first) {
+ builder.append(COMMA);
+ } else {
+ first = false;
+ }
+ Entry<Object, Object> entry = (Entry<Object, Object>) iterator.next();
+ encodeString(entry.getKey().toString(), builder);
+ builder.append(COLON);
+ encode(entry.getValue(), builder,null);
+ }
+ builder.append(BRACKET_RIGHT);
+ }
+
+ private void encodeList(List<Object> result, StringBuilder builder) throws JSONException {
+ boolean first = true;
+ builder.append(ARRAY_LEFT);
+ for (Iterator<Object> iterator = result.iterator(); iterator.hasNext();) {
+ if(!first) {
+ builder.append(COMMA);
+ } else {
+ first = false;
+ }
+
+ Object object = iterator.next();
+ encode(object, builder, null);
+ }
+ builder.append(ARRAY_RIGHT);
+ }
+
+ private String encodeObject(Object c, StringBuilder builder) throws JSONException {
+ if(c == null) {
+ return NULL;
+ }
+
+ if(c.getClass().getAnnotation(JSON.class) == null) {
+ return null;
+ }
+
+ builder.append(BRACKET_LEFT);
+
+ serializeFields(c, builder);
+ serializeMethods(c, builder);
+ builder.append(BRACKET_RIGHT);
+ return builder.toString();
+ }
+
+ private void serializeFields(Object c, StringBuilder builder)
+ throws JSONException {
+ boolean first = true;
+ Field[] fields = c.getClass().getDeclaredFields();
+ for (Field field : fields) {
+ Annotation[] anons = field.getAnnotations();
+ for (Annotation annotation : anons) {
+ if(annotation.annotationType().isAssignableFrom(JSON.class)) {
+ if(!first) {
+ builder.append(COMMA);
+ } else {
+ first = false;
+ }
+
+ String methodName = null;
+ // primitive boolean getters have is as prefix
+ // Use class.getComponentType instead of this
+ if(PRIMITIVE_BOOLEAN.equals(field.getType().toString())) {
+ methodName = JSONReflectionUtils.createGetter(field.getName(), JSONReflectionUtils.IS);
+ } else {
+ methodName = JSONReflectionUtils.createGetter(field.getName(), JSONReflectionUtils.GET);
+ }
+
+ try {
+ Method method = c.getClass().getMethod(methodName, (Class[])null);
+ Object result = method.invoke(c, (Object[])null);
+
+ encodeString(field.getName(), builder);
+ builder.append(COLON);
+ encode(result, builder,(JSON)annotation);
+ } catch (SecurityException e) {
+ throw new JSONException(e);
+ } catch (NoSuchMethodException e) {
+ throw new JSONException("No appropriate getter found: " + methodName ,e);
+ } catch (IllegalArgumentException e) {
+ throw new JSONException(e);
+ } catch (IllegalAccessException e) {
+ throw new JSONException(e);
+ } catch (InvocationTargetException e) {
+ throw new JSONException(e);
+ }
+ }
+ }
+ }
+ }
+
+ private void serializeMethods(Object c, StringBuilder builder) throws JSONException {
+ boolean first = true;
+ Method[] methods = c.getClass().getDeclaredMethods();
+ for (Method method : methods) {
+ Annotation[] anons = method.getAnnotations();
+ for (Annotation annotation : anons) {
+ if(annotation.annotationType().isAssignableFrom(JSON.class)) {
+ if(!first) {
+ builder.append(COMMA);
+ } else {
+ first = false;
+ }
+
+ try {
+ Object result = method.invoke(c, (Object[])null);
+ String name = method.getName();
+ if(name.startsWith("is")) {
+ name = name.replaceFirst("is", "");
+ name = name.substring(0, 1).toLowerCase() + name.substring(1);
+ }
+ if(name.startsWith("get")) {
+ name = name.replaceFirst("get", "");
+ name = name.substring(0, 1).toLowerCase() + name.substring(1);
+ }
+ encodeString(name, builder);
+ builder.append(COLON);
+ encode(result, builder, (JSON)annotation);
+ } catch (SecurityException e) {
+ throw new JSONException(e);
+ } catch (IllegalArgumentException e) {
+ throw new JSONException(e);
+ } catch (IllegalAccessException e) {
+ throw new JSONException(e);
+ } catch (InvocationTargetException e) {
+ throw new JSONException(e);
+ }
+ }
+ }
+ }
+ }
+
+ private void encodeString(String string, StringBuilder result) {
+ if(string == null) {
+ result.append(NULL);
+ } else {
+ result.append(QUOTE);
+ result.append(string);
+ result.append(QUOTE);
+ }
+ }
+
+ private void encodeInteger(Integer integer, StringBuilder result) {
+ if(integer == null) {
+ result.append(NULL);
+ } else {
+ result.append(EMTPY_STRING);
+ result.append(integer);
+ result.append(EMTPY_STRING);
+ }
+ }
+
+ private void encodeBoolean(Boolean b, StringBuilder result) {
+ if(b == null) {
+ result.append(NULL);
+ } else {
+ result.append(EMTPY_STRING);
+ result.append(Boolean.toString(b));
+ result.append(EMTPY_STRING);
+ }
+ }
+
+ private boolean hasInterface(Object target, Class<?> interfaceClass) {
+ Class<?>[] interfaces = target.getClass().getInterfaces();
+ for (int i = 0; i < interfaces.length; i++) {
+ if(interfaceClass.getName().equals(interfaces[i].getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+}
View
804 jjson/src/main/java/de/grobmeier/jjson/convert/JSONDecoder.java
@@ -1,402 +1,402 @@
-/*
- * Copyright 2007 Christian Grobmeier
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed
- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- * either express or implied. See the License for the specific
- * language governing permissions and limitations under the License.
- */
-package de.grobmeier.jjson.convert;
-
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.Locale;
-
-import de.grobmeier.jjson.JSONArray;
-import de.grobmeier.jjson.JSONBoolean;
-import de.grobmeier.jjson.JSONNull;
-import de.grobmeier.jjson.JSONNumber;
-import de.grobmeier.jjson.JSONObject;
-import de.grobmeier.jjson.JSONString;
-import de.grobmeier.jjson.JSONValue;
-
-/**
- *
- */
-public class JSONDecoder {
- // Use English locale, cause the json spec allows only . as seperator
- private static NumberFormat numberFormat =
- NumberFormat.getInstance(Locale.ENGLISH);
-
- private JSONReader reader = null;
- /**
- *
- */
- public JSONDecoder(final String json) {
- reader = new JSONReader(json);
- }
-
- /**
- * Special chars which open a type
- */
- enum Opener {
- OBJECT('{'),
- ARRAY('['),
- STRING('"'),
- PLUS('+'),
- MINUS('-'),
- DOT('.'),
- NULL('n'),
- NULL_UPPER('N'),
- TRUE('t'),
- TRUE_UPPER('T'),
- FALSE('f'),
- FALSE_UPPER('F');
-
- private char sign = ' ';
-
- private Opener(char s) {
- this.sign = s;
- }
- }
-
- /**
- * Special chars which close a type
- */
- enum Closer {
- jsonobject('}'), jsonarray(']'), jsonstring('"');
-
- private char sign = ' ';
-
- private Closer(char s) {
- this.sign = s;
- }
- }
-
- /**
- * JSONReader is a helper class to navigate
- * through the input json string.
- */
- private class JSONReader {
- /* chararray of the original jsonstring */
- private char[] json = null;
- /* pointer to the chararray */
- private int index = 0;
- /**
- * Constructor. Needs the orignal JSON-String
- * to navigate onto it.
- * @param _json the original JSON-String
- */
- public JSONReader(final String _json) {
- json = _json.trim().toCharArray();
- }
-
- /**
- * Reads one character and then points to the next sign.
- * @return the read character
- */
- public char read() {
- char result = ' ';
- if(json.length != 0) {
- result = json[index];
- }
-
- if(index + 1 < json.length) {
- index++;
- } else {
- index = 0;
- }
- return result;
- }
-
- /**
- * Moves the the cursor back one sign
- * or does nothing, if it is the first sign.
- * @return the current char after the operation
- */
- public char back() {
- if(index - 1 >= 0) {
- index--;
- } else {
- index = 0;
- }
- return current();
- }
-
- /**
- * Reads the current char without moving the cursor
- * @return the current char
- */
- public char current() {
- return json[index];
- }
-
- /**
- * Brings the pointer to the next position in the
- * array.
- * @return false, if the pointer is allready at the last char and
- * cannot be moved. True, if the the operation is successfull.
- */
- public boolean next() {
- if(index + 1 >= json.length) {
- return false;
- } else {
- index++;
- return true;
- }
- }
- /**
- * Reads the sign before the current postion without
- * moving the pointer. Returns a blank char if the
- * cursor is on the first position
- * @return the sign before the pointers position
- */
- public char readBefore() {
- if(index - 1 >= 0 && index < json.length) {
- return json[index-1];
- }
- return ' ';
- }
- }
-
- /**
- * @param c
- * @return
- */
- private boolean isOpener(char c) {
- if(reader.readBefore() == '\\') {
- return false;
- }
- Opener[] opener = Opener.values();
- for (Opener item : opener) {
- if(item.sign == c) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * @param c
- * @return
- */
- private boolean isCloser(char c) {
- if(reader.readBefore() == '\\') {
- return false;
- }
- Closer[] closer = Closer.values();
- for (Closer item : closer) {
- if(item.sign == c) {
- return true;
- }
- }
- return false;
- }
-
- public JSONValue decode() {
- char current = reader.current();
-
- if(current == Opener.OBJECT.sign) {
- return decodeObject();
- } else if(current == Opener.STRING.sign) {
- return decodeString();
- } else if(current == Opener.ARRAY.sign) {
- return decodeArray();
- } else if(
- Character.isDigit(current) ||
- current == Opener.MINUS.sign ||
- current == Opener.PLUS.sign ||
- current == Opener.DOT.sign) {
- return decodeNumber();
- } else if(
- current == Opener.NULL.sign ||
- current == Opener.NULL_UPPER.sign) {
- return decodeNull();
- } else if(
- current == Opener.FALSE.sign ||
- current == Opener.FALSE_UPPER.sign) {
- return decodeFalse();
- } else if(
- current == Opener.TRUE.sign ||
- current == Opener.TRUE_UPPER.sign) {
- return decodeTrue();
- }
- return null;
- }
-
- /**
- * @return
- */
- private JSONBoolean decodeTrue() {
- StringBuffer sb = new StringBuffer();
- sb.append(reader.current());
- int i = 1;
- while(i < 4) {
- reader.next();
- char temp = reader.current();
- sb.append(temp);
- i++;
- }
-
- // sanity check
- if(!"TRUE".equalsIgnoreCase(sb.toString())) {
- System.err.print("JSON expected true value, was: " + sb.toString());
- }
- return new JSONBoolean(true);
- }
-
- /**
- * @return
- */
- private JSONBoolean decodeFalse() {
- StringBuffer sb = new StringBuffer();
- sb.append(reader.current());
- int i = 1;
- while(i < 5) {
- reader.next();
- char temp = reader.current();
- sb.append(temp);
- i++;
- }
-
- // sanity check
- if(!"FALSE".equalsIgnoreCase(sb.toString())) {
- System.err.print("JSON expected true value, was: " + sb.toString());
- }
- return new JSONBoolean(false);
- }
-
- /**
- * @return
- */
- private JSONNull decodeNull() {
- StringBuffer sb = new StringBuffer();
- sb.append(reader.current());
- int i = 1;
- while(i < 4) {
- reader.next();
- char temp = reader.current();
- sb.append(temp);
- i++;
- }
-
- // sanity check
- if(!"NULL".equalsIgnoreCase(sb.toString())) {
- System.err.print("JSON expected null value, was: " + sb.toString());
- }
- return new JSONNull();
- }
-
- /**
- * @return
- */
- private JSONNumber decodeNumber() {
- StringBuffer sb = new StringBuffer();
- if(reader.current() != Opener.PLUS.sign) {
- sb.append(reader.current());
- }
-
- while(reader.next()) {
- char temp = reader.current();
- // Strings cannot have a opener inside
- if(isCloser(temp) || temp == ',') {
- break;
- } else {
- sb.append(temp);
- }
- }
-
- // Numbers have no closers, we have to point to the
- // last digit to work correctly for any surrounding objects/arrays
- reader.back();
-
- Number number = null;
- try {
- number = numberFormat.parse(sb.toString());
- } catch (ParseException e) {
- // TODO Integrate loggin
- e.printStackTrace();
- }
- // parsing to make sure the string is a number
- return new JSONNumber(number.toString());
- }
-
- /**
- * @return
- */
- private JSONObject decodeObject() {
- JSONObject result = new JSONObject();
-
- boolean hasNext = true;
- while(hasNext) {
- // key must be a string
- reader.next();
- JSONString key = decodeString();
-
- while(reader.next()) {
- char temp = reader.current();
- if(temp == ':') {
- reader.next();
- break;
- }
- }
-
- JSONValue value = decode();
- result.put(key.toString(), value);
- reader.next();
- if(reader.current() == Closer.jsonobject.sign) {
- hasNext = false;
- }
- }
- return result;
- }
-
- /**
- * @return
- */
- private JSONArray decodeArray() {
- JSONArray result = new JSONArray();
-
- boolean hasNext = true;
- while(hasNext) {
- // key must be a string
- reader.next();
- JSONValue value = decode();
- result.add(value);
- reader.next();
- if(reader.current() == Closer.jsonarray.sign) {
- hasNext = false;
- }
- }
- return result;
- }
-
- /**
- * @param input
- * @return
- */
- private JSONString decodeString() {
- StringBuilder result = new StringBuilder();
- if(reader.current() == Opener.STRING.sign) {
- while(reader.next()) {
- char temp = reader.current();
- // Strings cannot have a opener inside
- if(isCloser(temp)) {
- break;
- } else {
- result.append(temp);
- }
- }
- } else {
- return new JSONString("");
- }
- return new JSONString(result.toString());
- }
-}
+/*
+ * Copyright 2007 Christian Grobmeier
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+package de.grobmeier.jjson.convert;
+
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Locale;
+
+import de.grobmeier.jjson.JSONArray;
+import de.grobmeier.jjson.JSONBoolean;