/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2006-2022 the original author or authors.
*
* 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
*
* https://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 org.kordamp.json;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections4.map.ListOrderedMap;
import org.apache.commons.lang3.StringUtils;
import org.kordamp.ezmorph.Morpher;
import org.kordamp.ezmorph.array.ObjectArrayMorpher;
import org.kordamp.ezmorph.bean.BeanMorpher;
import org.kordamp.ezmorph.object.IdentityObjectMorpher;
import org.kordamp.json.processors.JsonBeanProcessor;
import org.kordamp.json.processors.JsonValueProcessor;
import org.kordamp.json.processors.JsonVerifier;
import org.kordamp.json.processors.PropertyNameProcessor;
import org.kordamp.json.regexp.RegexpUtils;
import org.kordamp.json.util.CycleDetectionStrategy;
import org.kordamp.json.util.EnumMorpher;
import org.kordamp.json.util.JSONTokener;
import org.kordamp.json.util.JSONUtils;
import org.kordamp.json.util.PropertyFilter;
import org.kordamp.json.util.PropertySetStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* A JSONObject is an unordered collection of name/value pairs. Its external
* form is a string wrapped in curly braces with colons between the names and
* values, and commas between the values and names. The internal form is an
* object having <code>get</code> and <code>opt</code> methods for accessing
* the values by name, and <code>put</code> methods for adding or replacing
* values by name. The values can be any of these types: <code>Boolean</code>,
* <code>JSONArray</code>, <code>JSONObject</code>, <code>Number</code>,
* <code>String</code>, or the <code>JSONNull</code> object. A JSONObject
* constructor can be used to convert an external form JSON text into an
* internal form whose values can be retrieved with the <code>get</code> and
* <code>opt</code> methods, or to convert values into a JSON text using the
* <code>element</code> and <code>toString</code> methods. A
* <code>get</code> method returns a value if one can be found, and throws an
* exception if one cannot be found. An <code>opt</code> method returns a
* default value instead of throwing an exception, and so is useful for
* obtaining optional values.
* <p/>
* The generic <code>get()</code> and <code>opt()</code> methods return an
* object, which you can cast or query for type. There are also typed
* <code>get</code> and <code>opt</code> methods that do type checking and
* type coercion for you.
* <p/>
* The <code>put</code> methods adds values to an object. For example,
* <p/>
* <pre>
* myString = new JSONObject().put("JSON", "Hello, World!").toString();</pre>
* <p/>
* produces the string <code>{"JSON": "Hello, World"}</code>.
* <p/>
* The texts produced by the <code>toString</code> methods strictly conform to
* the JSON syntax rules. The constructors are more forgiving in the texts they
* will accept:
* <ul>
* <li>An extra <code>,</code> <small>(comma)</small> may appear just
* before the closing brace.</li>
* <li>Strings may be quoted with <code>'</code> <small>(single quote)</small>.</li>
* <li>Strings do not need to be quoted at all if they do not begin with a
* quote or single quote, and if they do not contain leading or trailing spaces,
* and if they do not contain any of these characters:
* <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers and
* if they are not the reserved words <code>true</code>, <code>false</code>,
* or <code>null</code>.</li>
* <li>Keys can be followed by <code>=</code> or <code>=></code> as well as
* by <code>:</code>.</li>
* <li>Values can be followed by <code>;</code> <small>(semicolon)</small>
* as well as by <code>,</code> <small>(comma)</small>.</li>
* <li>Numbers may have the <code>0-</code> <small>(octal)</small> or
* <code>0x-</code> <small>(hex)</small> prefix.</li>
* <li>Comments written in the slashshlash, slashstar, and hash conventions
* will be ignored.</li>
* </ul>
*
* @author JSON.org
*/
public final class JSONObject extends AbstractJSON implements JSON, Map<String, Object>, Comparable {
private static final long serialVersionUID = 1997944501504436316L;
private static final Logger LOG = LoggerFactory.getLogger(JSONObject.class);
/**
* identifies this object as null
*/
private boolean nullObject;
/**
* The Map where the JSONObject's properties are kept.
*/
private Map properties;
/**
* Construct an empty JSONObject.
*/
public JSONObject() {
this.properties = new ListOrderedMap();
}
/**
* Creates a JSONObject that is null.
*/
public JSONObject(boolean isNull) {
this();
this.nullObject = isNull;
}
/**
* Creates a JSONObject.<br>
* Inspects the object type to call the correct JSONObject factory method.
* Accepts JSON formatted strings, Maps, DynaBeans and JavaBeans.
*
* @param object
*
* @throws JSONException if the object can not be converted to a proper
* JSONObject.
*/
public static JSONObject fromObject(Object object) {
return fromObject(object, new JsonConfig());
}
/**
* Creates a JSONObject.<br>
* Inspects the object type to call the correct JSONObject factory method.
* Accepts JSON formatted strings, Maps, DynaBeans and JavaBeans.
*
* @param object
*
* @throws JSONException if the object can not be converted to a proper
* JSONObject.
*/
public static JSONObject fromObject(Object object, JsonConfig jsonConfig) {
if (object == null || JSONUtils.isNull(object)) {
return new JSONObject(true);
} else if (object instanceof Enum) {
throw new JSONException("'object' is an Enum. Use JSONArray instead");
} else if (object instanceof Annotation || (object.getClass().isAnnotation())) {
throw new JSONException("'object' is an Annotation.");
} else if (object instanceof JSONObject) {
return Impl.fromJSONObject((JSONObject) object, jsonConfig);
} else if (object instanceof DynaBean) {
return Impl.fromDynaBean((DynaBean) object, jsonConfig);
} else if (object instanceof JSONTokener) {
return Impl.fromJSONTokener((JSONTokener) object, jsonConfig);
} else if (object instanceof JSONString) {
return Impl.fromJSONString((JSONString) object, jsonConfig);
} else if (object instanceof Map) {
return Impl.fromMap((Map) object, jsonConfig);
} else if (object instanceof String) {
return Impl.fromString((String) object, jsonConfig);
} else
没有合适的资源?快使用搜索试试~ 我知道了~
json lib最新源代码
共254个文件
java:182个
xml:12个
adoc:10个
需积分: 0 3 下载量 83 浏览量
2023-06-16
09:30:34
上传
评论
收藏 518KB ZIP 举报
温馨提示
json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json lib最新源代码json l
资源推荐
资源详情
资源评论
收起资源包目录
json lib最新源代码 (254个子文件)
usage.adoc 9KB
users.adoc 5KB
faq.adoc 3KB
groovy.adoc 2KB
introduction.adoc 2KB
README.adoc 1KB
index.adoc 557B
configuration.adoc 439B
compatibility.adoc 288B
_links.adoc 0B
gradlew.bat 3KB
style.css 39KB
stylesheet.css 11KB
SyntaxHighlighter.css 6KB
maven-base2.css 2KB
faq.fml 5KB
collapsed.gif 53B
expanded.gif 52B
.gitignore 132B
build.gradle 4KB
settings.gradle 2KB
json-lib-core.gradle 1KB
guide.gradle 1KB
gradlew 6KB
package.html 842B
package.html 827B
package.html 827B
package.html 818B
package.html 817B
package.html 812B
package.html 811B
overview.html 74B
idml_document.idms 44KB
gradle-wrapper.jar 58KB
JSONObject.java 105KB
JSONArray.java 93KB
TestJSONObject.java 67KB
XMLSerializer.java 63KB
TestJSONArray.java 53KB
JsonConfig.java 51KB
TestUserSubmitted.java 43KB
JSONUtils.java 29KB
TestJSONAssert.java 24KB
TestXMLSerializer_reads.java 24KB
TestXMLSerializer_writes.java 22KB
JSONAssert.java 21KB
TestJSONArrayCollections.java 17KB
Assertions.java 16KB
JSONTokener.java 15KB
TestUserSubmitted.java 11KB
AbstractJSON.java 10KB
TestJSONSerializer.java 10KB
JSONBuilder.java 9KB
TestJSONObjectJdk15.java 8KB
TestForcedArrayElementFlag.java 8KB
TestArrayAutoExpansion.java 7KB
TestJSONObjectEqualsHashCodeCompareTo.java 7KB
TestXMLSerializer_writes_with_autoexpansion.java 7KB
TestJSONObjectWithProcessors.java 7KB
TestJSONArrayCollection.java 7KB
JavaIdentifierTransformer.java 6KB
TestJSONUtils.java 6KB
JSONSerializer.java 5KB
TestJSONObjectEvents.java 5KB
JSONFunction.java 5KB
TestGenerics.java 5KB
WebUtils.java 5KB
TestJSONArrayJdk15.java 5KB
TestJSONArrayEvents.java 4KB
TestWebUtils.java 4KB
TestJSONArrayEqualsHashCodeCompareTo.java 4KB
TestJSONArrayAsList.java 4KB
PrimitiveBean.java 4KB
CycleDetectionStrategy.java 4KB
ObjectBean.java 4KB
TestJSONFunction.java 3KB
PropertyConstants.java 3KB
TestJsDateJsonBeanProcessor.java 3KB
TestJSONBuilder.java 3KB
JSON.java 3KB
TestJsDateJsonValueProcessor.java 3KB
TestJavaIdentifierTransformer.java 3KB
NumberBean.java 3KB
TestJSONStringer.java 3KB
AllTests.java 3KB
AbstractJSONArrayStaticBuildersTestCase.java 3KB
PropertySetStrategy.java 3KB
TestJSONTokener.java 3KB
NewBeanInstanceStrategy.java 3KB
TestDefaultValueProcessorMatcher.java 3KB
TestMappingPropertyFilter.java 3KB
JSONNull.java 3KB
TestIdmlParsing.java 3KB
JSONStringer.java 3KB
TestOrPropertyFilter.java 3KB
TestJsonVerifier.java 3KB
TestXmlContainingJSONSpecials.java 3KB
TestJSONObjectAsMap.java 3KB
GenericsBean.java 3KB
AbstractJSONTest.java 2KB
共 254 条
- 1
- 2
- 3
资源评论
Knowledgebase
- 粉丝: 181
- 资源: 50
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功