Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Aspectran is a lightweight Java framework for building Enterprise-ready Web applications.
Also, It will be able to launch as a Console-based and Embedded application.
/**
* Copyright 2008-2016 Juho Jeong
*
* 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 com.aspectran.core.util.json;
import java.io.Flushable;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import com.aspectran.core.util.BeanUtils;
import com.aspectran.core.util.apon.Parameter;
import com.aspectran.core.util.apon.ParameterValue;
import com.aspectran.core.util.apon.Parameters;
/**
* Converts an object to a JSON formatted string.
* If pretty-printing is enabled, includes spaces, tabs and new-lines to make the format more readable.
* Pretty-printing is disabled by default.
* The default indentation string is a tab character.
*
*
Created: 2008. 06. 12 PM 8:20:54
*
* @author Juho Jeong
*/
public class JsonWriter implements Flushable {
private Writer writer;
private boolean prettyPrint;
private String indentString;
private int indentDepth;
private boolean willWriteValue;
/**
* Instantiates a new JsonWriter.
* Pretty-printing is disabled by default.
*
* @param writer the character-output stream
*/
public JsonWriter(Writer writer) {
this(writer, false, null);
}
/**
* Instantiates a new JsonWriter.
* If pretty-printing is enabled, includes spaces, tabs and new-lines to make the format more readable.
* The default indentation string is a tab character.
*
* @param writer the character-output stream
* @param prettyPrint enables or disables pretty-printing
*/
public JsonWriter(Writer writer, boolean prettyPrint) {
this(writer, prettyPrint, "\t");
}
/**
* Instantiates a new JsonWriter.
* If pretty-printing is enabled, includes spaces, tabs and new-lines to make the format more readable.
*
* @param writer the character-output stream
* @param prettyPrint enables or disables pretty-printing
* @param indentString the string that should be used for indentation when pretty-printing is enabled
*/
public JsonWriter(Writer writer, boolean prettyPrint, String indentString) {
this.writer = writer;
this.prettyPrint = prettyPrint;
this.indentString = indentString;
}
/**
* Write an object to a character stream.
*
* @param object the object to write to a character-output stream.
* @throws IOException an I/O error occurs.
* @throws InvocationTargetException the invocation target exception
*/
public void write(Object object) throws IOException, InvocationTargetException {
if(object == null) {
writeNull();
} else if(object instanceof String ||
object instanceof Date) {
writeString(object.toString());
} else if(object instanceof Boolean) {
writeBoolean((Boolean)object);
} else if(object instanceof Number) {
writeNumber((Number)object);
} else if(object instanceof Parameters) {
openCurlyBracket();
Map params = ((Parameters)object).getParameterValueMap();
Iterator iter = params.values().iterator();
while(iter.hasNext()) {
Parameter p = iter.next();
String name = p.getName();
Object value = p.getValue();
checkCircularReference(object, value);
writeName(name);
write(value);
if(iter.hasNext()) {
writeComma();
}
}
closeCurlyBracket();
} else if(object instanceof Map, ?>) {
openCurlyBracket();
@SuppressWarnings("unchecked")
Iterator> iter = ((Map