mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -36,7 +36,7 @@ public final class InternalJSONUtil {
|
||||
* @return 检测后的值
|
||||
* @throws JSONException If o is a non-finite number.
|
||||
*/
|
||||
static Object testValidity(Object obj) throws JSONException {
|
||||
static Object testValidity(final Object obj) throws JSONException {
|
||||
if (false == ObjUtil.isValidIfNumber(obj)) {
|
||||
throw new JSONException("JSON does not allow non-finite numbers.");
|
||||
}
|
||||
@@ -58,14 +58,14 @@ public final class InternalJSONUtil {
|
||||
* @return 字符串
|
||||
* @throws JSONException If the value is or contains an invalid number.
|
||||
*/
|
||||
static String valueToString(Object value) throws JSONException {
|
||||
static String valueToString(final Object value) throws JSONException {
|
||||
if (value == null || value instanceof JSONNull) {
|
||||
return JSONNull.NULL.toString();
|
||||
}
|
||||
if (value instanceof JSONString) {
|
||||
try {
|
||||
return ((JSONString) value).toJSONString();
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
} else if (value instanceof Number) {
|
||||
@@ -73,10 +73,10 @@ public final class InternalJSONUtil {
|
||||
} else if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) {
|
||||
return value.toString();
|
||||
} else if (value instanceof Map) {
|
||||
Map<?, ?> map = (Map<?, ?>) value;
|
||||
final Map<?, ?> map = (Map<?, ?>) value;
|
||||
return new JSONObject(map).toString();
|
||||
} else if (value instanceof Collection) {
|
||||
Collection<?> coll = (Collection<?>) value;
|
||||
final Collection<?> coll = (Collection<?>) value;
|
||||
return new JSONArray(coll).toString();
|
||||
} else if (ArrayUtil.isArray(value)) {
|
||||
return new JSONArray(value).toString();
|
||||
@@ -91,7 +91,7 @@ public final class InternalJSONUtil {
|
||||
* @param string A String.
|
||||
* @return A simple JSON value.
|
||||
*/
|
||||
public static Object stringToValue(String string) {
|
||||
public static Object stringToValue(final String string) {
|
||||
// null处理
|
||||
if (StrUtil.isEmpty(string) || StrUtil.NULL.equalsIgnoreCase(string)) {
|
||||
return JSONNull.NULL;
|
||||
@@ -106,7 +106,7 @@ public final class InternalJSONUtil {
|
||||
}
|
||||
|
||||
// Number处理
|
||||
char b = string.charAt(0);
|
||||
final char b = string.charAt(0);
|
||||
if ((b >= '0' && b <= '9') || b == '-') {
|
||||
try {
|
||||
if (StrUtil.containsAnyIgnoreCase(string, ".", "e")) {
|
||||
@@ -122,7 +122,7 @@ public final class InternalJSONUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
} catch (final Exception ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,12 +140,12 @@ public final class InternalJSONUtil {
|
||||
* @param value 值
|
||||
* @return JSONObject
|
||||
*/
|
||||
static JSONObject propertyPut(JSONObject jsonObject, Object key, Object value, Filter<MutablePair<String, Object>> filter) {
|
||||
static JSONObject propertyPut(final JSONObject jsonObject, final Object key, final Object value, final Filter<MutablePair<String, Object>> filter) {
|
||||
final String[] path = StrUtil.splitToArray(Convert.toStr(key), CharUtil.DOT);
|
||||
int last = path.length - 1;
|
||||
final int last = path.length - 1;
|
||||
JSONObject target = jsonObject;
|
||||
for (int i = 0; i < last; i += 1) {
|
||||
String segment = path[i];
|
||||
final String segment = path[i];
|
||||
JSONObject nextTarget = target.getJSONObject(segment);
|
||||
if (nextTarget == null) {
|
||||
nextTarget = new JSONObject(target.getConfig());
|
||||
@@ -170,7 +170,7 @@ public final class InternalJSONUtil {
|
||||
* @return 是否忽略null值
|
||||
* @since 4.3.1
|
||||
*/
|
||||
static boolean defaultIgnoreNullValue(Object obj) {
|
||||
static boolean defaultIgnoreNullValue(final Object obj) {
|
||||
return (false == (obj instanceof CharSequence))//
|
||||
&& (false == (obj instanceof JSONTokener))//
|
||||
&& (false == (obj instanceof Map));
|
||||
@@ -183,7 +183,7 @@ public final class InternalJSONUtil {
|
||||
* @return {@link CopyOptions}
|
||||
* @since 5.8.0
|
||||
*/
|
||||
static CopyOptions toCopyOptions(JSONConfig config) {
|
||||
static CopyOptions toCopyOptions(final JSONConfig config) {
|
||||
return CopyOptions.create()
|
||||
.setIgnoreCase(config.isIgnoreCase())
|
||||
.setIgnoreError(config.isIgnoreError())
|
||||
@@ -198,8 +198,8 @@ public final class InternalJSONUtil {
|
||||
* @param config JSON配置项,{@code null}则使用默认配置
|
||||
* @return Map
|
||||
*/
|
||||
static Map<String, Object> createRawMap(int capacity, JSONConfig config) {
|
||||
Map<String, Object> rawHashMap;
|
||||
static Map<String, Object> createRawMap(final int capacity, JSONConfig config) {
|
||||
final Map<String, Object> rawHashMap;
|
||||
if (null == config) {
|
||||
config = JSONConfig.create();
|
||||
}
|
||||
|
@@ -106,7 +106,7 @@ public interface JSON extends Cloneable, Serializable {
|
||||
* @return JSON字符串
|
||||
* @throws JSONException 包含非法数抛出此异常
|
||||
*/
|
||||
default String toJSONString(int indentFactor) throws JSONException {
|
||||
default String toJSONString(final int indentFactor) throws JSONException {
|
||||
final StringWriter sw = new StringWriter();
|
||||
synchronized (sw.getBuffer()) {
|
||||
return this.write(sw, indentFactor, 0).toString();
|
||||
@@ -121,7 +121,7 @@ public interface JSON extends Cloneable, Serializable {
|
||||
* @return Writer
|
||||
* @throws JSONException JSON相关异常
|
||||
*/
|
||||
default Writer write(Writer writer) throws JSONException {
|
||||
default Writer write(final Writer writer) throws JSONException {
|
||||
return this.write(writer, 0, 0);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public interface JSON extends Cloneable, Serializable {
|
||||
* @param clazz 实体类
|
||||
* @return 实体类对象
|
||||
*/
|
||||
default <T> T toBean(Class<T> clazz) {
|
||||
default <T> T toBean(final Class<T> clazz) {
|
||||
return toBean((Type) clazz);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public interface JSON extends Cloneable, Serializable {
|
||||
* @return 实体类对象
|
||||
* @since 4.2.2
|
||||
*/
|
||||
default <T> T toBean(TypeReference<T> reference) {
|
||||
default <T> T toBean(final TypeReference<T> reference) {
|
||||
return toBean(reference.getType());
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ public interface JSON extends Cloneable, Serializable {
|
||||
* @return 实体类对象
|
||||
* @since 3.0.8
|
||||
*/
|
||||
default <T> T toBean(Type type) {
|
||||
default <T> T toBean(final Type type) {
|
||||
return toBean(type, false);
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public interface JSON extends Cloneable, Serializable {
|
||||
* @return 实体类对象
|
||||
* @since 4.3.2
|
||||
*/
|
||||
default <T> T toBean(Type type, boolean ignoreError) {
|
||||
default <T> T toBean(final Type type, final boolean ignoreError) {
|
||||
return JSONConverter.jsonConvert(type, this, ignoreError);
|
||||
}
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @param initialCapacity 初始大小
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public JSONArray(int initialCapacity) {
|
||||
public JSONArray(final int initialCapacity) {
|
||||
this(initialCapacity, JSONConfig.create());
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @param config JSON配置项
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public JSONArray(JSONConfig config) {
|
||||
public JSONArray(final JSONConfig config) {
|
||||
this(DEFAULT_CAPACITY, config);
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @param config JSON配置项
|
||||
* @since 4.1.19
|
||||
*/
|
||||
public JSONArray(int initialCapacity, JSONConfig config) {
|
||||
public JSONArray(final int initialCapacity, final JSONConfig config) {
|
||||
this.rawList = new ArrayList<>(initialCapacity);
|
||||
this.config = ObjUtil.defaultIfNull(config, JSONConfig::create);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @param object 数组或集合或JSON数组字符串
|
||||
* @throws JSONException 非数组或集合
|
||||
*/
|
||||
public JSONArray(Object object) throws JSONException {
|
||||
public JSONArray(final Object object) throws JSONException {
|
||||
this(object, JSONConfig.create());
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @throws JSONException 非数组或集合
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public JSONArray(Object object, JSONConfig jsonConfig) throws JSONException {
|
||||
public JSONArray(final Object object, final JSONConfig jsonConfig) throws JSONException {
|
||||
this(object, jsonConfig, null);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @throws JSONException 非数组或集合
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public JSONArray(Object object, JSONConfig jsonConfig, Filter<Mutable<Object>> filter) throws JSONException {
|
||||
public JSONArray(final Object object, final JSONConfig jsonConfig, final Filter<Mutable<Object>> filter) throws JSONException {
|
||||
this(DEFAULT_CAPACITY, jsonConfig);
|
||||
ObjectMapper.of(object).map(this, filter);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return this
|
||||
* @since 4.1.19
|
||||
*/
|
||||
public JSONArray setDateFormat(String format) {
|
||||
public JSONArray setDateFormat(final String format) {
|
||||
this.config.setDateFormat(format);
|
||||
return this;
|
||||
}
|
||||
@@ -175,33 +175,33 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return a string.
|
||||
* @throws JSONException If the array contains an invalid number.
|
||||
*/
|
||||
public String join(String separator) throws JSONException {
|
||||
public String join(final String separator) throws JSONException {
|
||||
return StrJoiner.of(separator)
|
||||
.append(this, InternalJSONUtil::valueToString).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
public Object get(final int index) {
|
||||
return this.rawList.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObj(Integer index, Object defaultValue) {
|
||||
public Object getObj(final Integer index, final Object defaultValue) {
|
||||
return (index < 0 || index >= this.size()) ? defaultValue : this.rawList.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getByPath(String expression) {
|
||||
public Object getByPath(final String expression) {
|
||||
return BeanPath.create(expression).get(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getByPath(String expression, Class<T> resultType) {
|
||||
public <T> T getByPath(final String expression, final Class<T> resultType) {
|
||||
return JSONConverter.jsonConvert(resultType, getByPath(expression), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putByPath(String expression, Object value) {
|
||||
public void putByPath(final String expression, final Object value) {
|
||||
BeanPath.create(expression).set(this, value);
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return this.
|
||||
* @see #set(Object)
|
||||
*/
|
||||
public JSONArray put(Object value) {
|
||||
public JSONArray put(final Object value) {
|
||||
return set(value);
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return this.
|
||||
* @since 5.2.5
|
||||
*/
|
||||
public JSONArray set(Object value) {
|
||||
public JSONArray set(final Object value) {
|
||||
this.add(value);
|
||||
return this;
|
||||
}
|
||||
@@ -239,13 +239,13 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @throws JSONException index < 0 或者非有限的数字
|
||||
* @see #set(int, Object)
|
||||
*/
|
||||
public JSONArray put(int index, Object value) throws JSONException {
|
||||
public JSONArray put(final int index, final Object value) throws JSONException {
|
||||
this.set(index, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toBean(Type type) {
|
||||
public <T> T toBean(final Type type) {
|
||||
return JSON.super.toBean(type, config.isIgnoreError());
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return A JSONObject,无名或值返回null
|
||||
* @throws JSONException 如果任何一个名为null
|
||||
*/
|
||||
public JSONObject toJSONObject(JSONArray names) throws JSONException {
|
||||
public JSONObject toJSONObject(final JSONArray names) throws JSONException {
|
||||
if (names == null || names.size() == 0 || this.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -276,7 +276,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
@@ -320,7 +320,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
public boolean contains(final Object o) {
|
||||
return rawList.contains(o);
|
||||
}
|
||||
|
||||
@@ -331,61 +331,61 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <T> T[] toArray(T[] a) {
|
||||
public <T> T[] toArray(final T[] a) {
|
||||
return (T[]) JSONConverter.toArray(this, a.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(Object e) {
|
||||
public boolean add(final Object e) {
|
||||
return addRaw(JSONUtil.wrap(e, this.config), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(int index) {
|
||||
public Object remove(final int index) {
|
||||
return index >= 0 && index < this.size() ? this.rawList.remove(index) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
public boolean remove(final Object o) {
|
||||
return rawList.remove(o);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"NullableProblems", "SlowListContainsAll"})
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
public boolean containsAll(final Collection<?> c) {
|
||||
return rawList.containsAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<?> c) {
|
||||
public boolean addAll(final Collection<?> c) {
|
||||
if (CollUtil.isEmpty(c)) {
|
||||
return false;
|
||||
}
|
||||
for (Object obj : c) {
|
||||
for (final Object obj : c) {
|
||||
this.add(obj);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<?> c) {
|
||||
public boolean addAll(final int index, final Collection<?> c) {
|
||||
if (CollUtil.isEmpty(c)) {
|
||||
return false;
|
||||
}
|
||||
final ArrayList<Object> list = new ArrayList<>(c.size());
|
||||
for (Object object : c) {
|
||||
for (final Object object : c) {
|
||||
list.add(JSONUtil.wrap(object, this.config));
|
||||
}
|
||||
return rawList.addAll(index, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
public boolean removeAll(final Collection<?> c) {
|
||||
return this.rawList.removeAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
public boolean retainAll(final Collection<?> c) {
|
||||
return this.rawList.retainAll(c);
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return 替换的值,即之前的值
|
||||
*/
|
||||
@Override
|
||||
public Object set(int index, Object element) {
|
||||
public Object set(final int index, final Object element) {
|
||||
return set(index, element, null);
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return 替换的值,即之前的值
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public Object set(int index, Object element, Filter<MutablePair<Integer, Object>> filter) {
|
||||
public Object set(final int index, Object element, final Filter<MutablePair<Integer, Object>> filter) {
|
||||
// 添加前置过滤,通过MutablePair实现过滤、修改键值对等
|
||||
if (null != filter) {
|
||||
final MutablePair<Integer, Object> pair = new MutablePair<>(index, element);
|
||||
@@ -433,7 +433,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, Object element) {
|
||||
public void add(final int index, final Object element) {
|
||||
if (index < 0) {
|
||||
throw new JSONException("JSONArray[{}] not found.", index);
|
||||
}
|
||||
@@ -450,12 +450,12 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
public int indexOf(final Object o) {
|
||||
return this.rawList.indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
public int lastIndexOf(final Object o) {
|
||||
return this.rawList.lastIndexOf(o);
|
||||
}
|
||||
|
||||
@@ -465,12 +465,12 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<Object> listIterator(int index) {
|
||||
public ListIterator<Object> listIterator(final int index) {
|
||||
return this.rawList.listIterator(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> subList(int fromIndex, int toIndex) {
|
||||
public List<Object> subList(final int fromIndex, final int toIndex) {
|
||||
return this.rawList.subList(fromIndex, toIndex);
|
||||
}
|
||||
|
||||
@@ -480,7 +480,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @param arrayClass 数组元素类型
|
||||
* @return 实体类对象
|
||||
*/
|
||||
public Object toArray(Class<?> arrayClass) {
|
||||
public Object toArray(final Class<?> arrayClass) {
|
||||
return JSONConverter.toArray(this, arrayClass);
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return {@link ArrayList}
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public <T> List<T> toList(Class<T> elementType) {
|
||||
public <T> List<T> toList(final Class<T> elementType) {
|
||||
return JSONConverter.toList(this, elementType);
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return JSON字符串
|
||||
* @since 5.7.15
|
||||
*/
|
||||
public String toJSONString(int indentFactor, Filter<MutablePair<Integer, Object>> filter) {
|
||||
public String toJSONString(final int indentFactor, final Filter<MutablePair<Integer, Object>> filter) {
|
||||
final StringWriter sw = new StringWriter();
|
||||
synchronized (sw.getBuffer()) {
|
||||
return this.write(sw, indentFactor, 0, filter).toString();
|
||||
@@ -523,7 +523,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
|
||||
public Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException {
|
||||
return write(writer, indentFactor, indent, null);
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @throws JSONException JSON相关异常
|
||||
* @since 5.7.15
|
||||
*/
|
||||
public Writer write(Writer writer, int indentFactor, int indent, Filter<MutablePair<Integer, Object>> filter) throws JSONException {
|
||||
public Writer write(final Writer writer, final int indentFactor, final int indent, final Filter<MutablePair<Integer, Object>> filter) throws JSONException {
|
||||
final JSONWriter jsonWriter = JSONWriter.of(writer, indentFactor, indent, config)
|
||||
.beginArray();
|
||||
|
||||
@@ -569,7 +569,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
* @return 是否加入成功
|
||||
* @since 5.8.0
|
||||
*/
|
||||
protected boolean addRaw(Object obj, Filter<Mutable<Object>> filter) {
|
||||
protected boolean addRaw(Object obj, final Filter<Mutable<Object>> filter) {
|
||||
// 添加前置过滤,通过MutablePair实现过滤、修改键值对等
|
||||
if (null != filter) {
|
||||
final Mutable<Object> mutable = new MutableObj<>(obj);
|
||||
|
@@ -82,7 +82,7 @@ public class JSONConfig implements Serializable {
|
||||
* @return this
|
||||
* @since 5.7.21
|
||||
*/
|
||||
public JSONConfig setKeyComparator(Comparator<String> keyComparator) {
|
||||
public JSONConfig setKeyComparator(final Comparator<String> keyComparator) {
|
||||
this.keyComparator = keyComparator;
|
||||
return this;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class JSONConfig implements Serializable {
|
||||
* @param ignoreError 是否忽略转换过程中的异常
|
||||
* @return this
|
||||
*/
|
||||
public JSONConfig setIgnoreError(boolean ignoreError) {
|
||||
public JSONConfig setIgnoreError(final boolean ignoreError) {
|
||||
this.ignoreError = ignoreError;
|
||||
return this;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class JSONConfig implements Serializable {
|
||||
* @param ignoreCase 是否忽略键的大小写
|
||||
* @return this
|
||||
*/
|
||||
public JSONConfig setIgnoreCase(boolean ignoreCase) {
|
||||
public JSONConfig setIgnoreCase(final boolean ignoreCase) {
|
||||
this.ignoreCase = ignoreCase;
|
||||
return this;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class JSONConfig implements Serializable {
|
||||
* @param dateFormat 日期格式,null表示默认的时间戳
|
||||
* @return this
|
||||
*/
|
||||
public JSONConfig setDateFormat(String dateFormat) {
|
||||
public JSONConfig setDateFormat(final String dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
return this;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class JSONConfig implements Serializable {
|
||||
* @param ignoreNullValue 是否忽略null值
|
||||
* @return this
|
||||
*/
|
||||
public JSONConfig setIgnoreNullValue(boolean ignoreNullValue) {
|
||||
public JSONConfig setIgnoreNullValue(final boolean ignoreNullValue) {
|
||||
this.ignoreNullValue = ignoreNullValue;
|
||||
return this;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class JSONConfig implements Serializable {
|
||||
* @return this
|
||||
* @since 5.4.2
|
||||
*/
|
||||
public JSONConfig setTransientSupport(boolean transientSupport) {
|
||||
public JSONConfig setTransientSupport(final boolean transientSupport) {
|
||||
this.transientSupport = transientSupport;
|
||||
return this;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ public class JSONConfig implements Serializable {
|
||||
* @return this
|
||||
* @since 5.6.2
|
||||
*/
|
||||
public JSONConfig setStripTrailingZeros(boolean stripTrailingZeros) {
|
||||
public JSONConfig setStripTrailingZeros(final boolean stripTrailingZeros) {
|
||||
this.stripTrailingZeros = stripTrailingZeros;
|
||||
return this;
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ public class JSONConverter implements Converter<JSON> {
|
||||
|
||||
static {
|
||||
// 注册到转换中心
|
||||
ConverterRegistry registry = ConverterRegistry.getInstance();
|
||||
final ConverterRegistry registry = ConverterRegistry.getInstance();
|
||||
registry.putCustom(JSON.class, JSONConverter.class);
|
||||
registry.putCustom(JSONObject.class, JSONConverter.class);
|
||||
registry.putCustom(JSONArray.class, JSONConverter.class);
|
||||
@@ -40,7 +40,7 @@ public class JSONConverter implements Converter<JSON> {
|
||||
* @param arrayClass 数组元素类型
|
||||
* @return 数组对象
|
||||
*/
|
||||
protected static Object toArray(JSONArray jsonArray, Class<?> arrayClass) {
|
||||
protected static Object toArray(final JSONArray jsonArray, final Class<?> arrayClass) {
|
||||
return new ArrayConverter(arrayClass).convert(jsonArray, null);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class JSONConverter implements Converter<JSON> {
|
||||
* @param elementType 对象元素类型
|
||||
* @return 对象列表
|
||||
*/
|
||||
protected static <T> List<T> toList(JSONArray jsonArray, Class<T> elementType) {
|
||||
protected static <T> List<T> toList(final JSONArray jsonArray, final Class<T> elementType) {
|
||||
return Convert.toList(elementType, jsonArray);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class JSONConverter implements Converter<JSON> {
|
||||
* @throws ConvertException 转换失败
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static <T> T jsonConvert(Type targetType, Object value, boolean ignoreError) throws ConvertException {
|
||||
protected static <T> T jsonConvert(final Type targetType, final Object value, final boolean ignoreError) throws ConvertException {
|
||||
if (JSONUtil.isNull(value)) {
|
||||
return null;
|
||||
}
|
||||
@@ -78,8 +78,7 @@ public class JSONConverter implements Converter<JSON> {
|
||||
if(targetType instanceof Class){
|
||||
final Class<?> clazz = (Class<?>) targetType;
|
||||
if (JSONBeanParser.class.isAssignableFrom(clazz)){
|
||||
@SuppressWarnings("rawtypes")
|
||||
JSONBeanParser target = (JSONBeanParser) ReflectUtil.newInstanceIfPossible(clazz);
|
||||
@SuppressWarnings("rawtypes") final JSONBeanParser target = (JSONBeanParser) ReflectUtil.newInstanceIfPossible(clazz);
|
||||
if(null == target){
|
||||
throw new ConvertException("Can not instance [{}]", targetType);
|
||||
}
|
||||
@@ -104,7 +103,7 @@ public class JSONConverter implements Converter<JSON> {
|
||||
* @since 5.7.10
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected static <T> T jsonToBean(Type targetType, Object value, boolean ignoreError) throws ConvertException {
|
||||
protected static <T> T jsonToBean(final Type targetType, final Object value, final boolean ignoreError) throws ConvertException {
|
||||
if (JSONUtil.isNull(value)) {
|
||||
return null;
|
||||
}
|
||||
@@ -142,7 +141,7 @@ public class JSONConverter implements Converter<JSON> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSON convert(Object value, JSON defaultValue) throws IllegalArgumentException {
|
||||
public JSON convert(final Object value, final JSON defaultValue) throws IllegalArgumentException {
|
||||
return JSONUtil.parse(value);
|
||||
}
|
||||
}
|
||||
|
@@ -12,27 +12,27 @@ import cn.hutool.core.text.StrUtil;
|
||||
public class JSONException extends RuntimeException {
|
||||
private static final long serialVersionUID = 0;
|
||||
|
||||
public JSONException(Throwable e) {
|
||||
public JSONException(final Throwable e) {
|
||||
super(ExceptionUtil.getMessage(e), e);
|
||||
}
|
||||
|
||||
public JSONException(String message) {
|
||||
public JSONException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JSONException(String messageTemplate, Object... params) {
|
||||
public JSONException(final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params));
|
||||
}
|
||||
|
||||
public JSONException(String message, Throwable cause) {
|
||||
public JSONException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JSONException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) {
|
||||
public JSONException(final String message, final Throwable throwable, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||
super(message, throwable, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public JSONException(Throwable throwable, String messageTemplate, Object... params) {
|
||||
public JSONException(final Throwable throwable, final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params), throwable);
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @param key 键
|
||||
* @return true 无此key或值为{@code null}或{@link JSONNull#NULL}返回{@code false},其它返回{@code true}
|
||||
*/
|
||||
default boolean isNull(K key) {
|
||||
default boolean isNull(final K key) {
|
||||
return JSONUtil.isNull(this.getObj(key));
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @return 字符串类型值
|
||||
* @since 4.2.2
|
||||
*/
|
||||
default String getStrEscaped(K key) {
|
||||
default String getStrEscaped(final K key) {
|
||||
return getStrEscaped(key, null);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @return 字符串类型值
|
||||
* @since 4.2.2
|
||||
*/
|
||||
default String getStrEscaped(K key, String defaultValue) {
|
||||
default String getStrEscaped(final K key, final String defaultValue) {
|
||||
return JSONUtil.escape(getStr(key, defaultValue));
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @param key KEY
|
||||
* @return JSONArray对象,如果值为{@code null},返回{@code null},非JSONArray类型,尝试转换,转换失败抛出异常
|
||||
*/
|
||||
default JSONArray getJSONArray(K key) {
|
||||
default JSONArray getJSONArray(final K key) {
|
||||
final Object object = this.getObj(key);
|
||||
if (JSONUtil.isNull(object)) {
|
||||
return null;
|
||||
@@ -87,7 +87,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @param key KEY
|
||||
* @return JSONObject对象,如果值为{@code null},返回{@code null},非JSONObject类型,尝试转换,转换失败抛出异常
|
||||
*/
|
||||
default JSONObject getJSONObject(K key) {
|
||||
default JSONObject getJSONObject(final K key) {
|
||||
final Object object = this.getObj(key);
|
||||
if (JSONUtil.isNull(object)) {
|
||||
return null;
|
||||
@@ -109,7 +109,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @return Bean对象,如果值为null或者非JSONObject类型,返回null
|
||||
* @since 3.1.1
|
||||
*/
|
||||
default <T> T getBean(K key, Class<T> beanType) {
|
||||
default <T> T getBean(final K key, final Class<T> beanType) {
|
||||
final JSONObject obj = getJSONObject(key);
|
||||
return (null == obj) ? null : obj.toBean(beanType);
|
||||
}
|
||||
@@ -124,13 +124,13 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @return Bean的List,如果值为null或者非JSONObject类型,返回null
|
||||
* @since 5.7.20
|
||||
*/
|
||||
default <T> List<T> getBeanList(K key, Class<T> beanType) {
|
||||
default <T> List<T> getBeanList(final K key, final Class<T> beanType) {
|
||||
final JSONArray jsonArray = getJSONArray(key);
|
||||
return (null == jsonArray) ? null : jsonArray.toList(beanType);
|
||||
}
|
||||
|
||||
@Override
|
||||
default Date getDate(K key, Date defaultValue) {
|
||||
default Date getDate(final K key, final Date defaultValue) {
|
||||
// 默认转换
|
||||
final Object obj = getObj(key);
|
||||
if (JSONUtil.isNull(obj)) {
|
||||
@@ -164,7 +164,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @return {@link LocalDateTime}
|
||||
* @since 5.7.7
|
||||
*/
|
||||
default LocalDateTime getLocalDateTime(K key, LocalDateTime defaultValue) {
|
||||
default LocalDateTime getLocalDateTime(final K key, final LocalDateTime defaultValue) {
|
||||
// 默认转换
|
||||
final Object obj = getObj(key);
|
||||
if (JSONUtil.isNull(obj)) {
|
||||
@@ -201,7 +201,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @throws ConvertException 转换异常
|
||||
* @since 3.0.8
|
||||
*/
|
||||
default <T> T get(K key, Class<T> type) throws ConvertException {
|
||||
default <T> T get(final K key, final Class<T> type) throws ConvertException {
|
||||
return get(key, type, false);
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
|
||||
* @throws ConvertException 转换异常
|
||||
* @since 3.0.8
|
||||
*/
|
||||
default <T> T get(K key, Class<T> type, boolean ignoreError) throws ConvertException {
|
||||
default <T> T get(final K key, final Class<T> type, final boolean ignoreError) throws ConvertException {
|
||||
final Object value = this.getObj(key);
|
||||
if (JSONUtil.isNull(value)) {
|
||||
return null;
|
||||
|
@@ -29,7 +29,7 @@ public class JSONNull implements Serializable {
|
||||
*/
|
||||
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
public boolean equals(final Object object) {
|
||||
return object == null || (object == this);
|
||||
}
|
||||
|
||||
|
@@ -55,7 +55,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @param config JSON配置项
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public JSONObject(JSONConfig config) {
|
||||
public JSONObject(final JSONConfig config) {
|
||||
this(DEFAULT_CAPACITY, config);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @param config JSON配置项,{@code null}则使用默认配置
|
||||
* @since 4.1.19
|
||||
*/
|
||||
public JSONObject(int capacity, JSONConfig config) {
|
||||
public JSONObject(final int capacity, final JSONConfig config) {
|
||||
super(InternalJSONUtil.createRawMap(capacity, ObjUtil.defaultIfNull(config, JSONConfig.create())));
|
||||
this.config = ObjUtil.defaultIfNull(config, JSONConfig.create());
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
*
|
||||
* @param source JavaBean或者Map对象或者String
|
||||
*/
|
||||
public JSONObject(Object source) {
|
||||
public JSONObject(final Object source) {
|
||||
this(source, JSONConfig.create().setIgnoreNullValue(InternalJSONUtil.defaultIgnoreNullValue(source)));
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @param config JSON配置文件,{@code null}则使用默认配置
|
||||
* @since 4.2.2
|
||||
*/
|
||||
public JSONObject(Object source, JSONConfig config) {
|
||||
public JSONObject(final Object source, final JSONConfig config) {
|
||||
this(source, config, null);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对键值对的过滤和修改操作,{@code null}表示不过滤
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public JSONObject(Object source, JSONConfig config, Filter<MutablePair<String, Object>> filter) {
|
||||
public JSONObject(final Object source, final JSONConfig config, final Filter<MutablePair<String, Object>> filter) {
|
||||
this(DEFAULT_CAPACITY, config);
|
||||
ObjectMapper.of(source).map(this, filter);
|
||||
}
|
||||
@@ -145,13 +145,13 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return this
|
||||
* @since 4.1.19
|
||||
*/
|
||||
public JSONObject setDateFormat(String format) {
|
||||
public JSONObject setDateFormat(final String format) {
|
||||
this.config.setDateFormat(format);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toBean(Type type) {
|
||||
public <T> T toBean(final Type type) {
|
||||
return JSON.super.toBean(type, this.config.isIgnoreError());
|
||||
}
|
||||
|
||||
@@ -162,13 +162,13 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return A JSONArray of values.
|
||||
* @throws JSONException If any of the values are non-finite numbers.
|
||||
*/
|
||||
public JSONArray toJSONArray(Collection<String> names) throws JSONException {
|
||||
public JSONArray toJSONArray(final Collection<String> names) throws JSONException {
|
||||
if (CollUtil.isEmpty(names)) {
|
||||
return null;
|
||||
}
|
||||
final JSONArray ja = new JSONArray(this.config);
|
||||
Object value;
|
||||
for (String name : names) {
|
||||
for (final String name : names) {
|
||||
value = this.get(name);
|
||||
if (null != value) {
|
||||
ja.set(value);
|
||||
@@ -178,22 +178,22 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getObj(String key, Object defaultValue) {
|
||||
public Object getObj(final String key, final Object defaultValue) {
|
||||
return this.getOrDefault(key, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getByPath(String expression) {
|
||||
public Object getByPath(final String expression) {
|
||||
return BeanPath.create(expression).get(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getByPath(String expression, Class<T> resultType) {
|
||||
public <T> T getByPath(final String expression, final Class<T> resultType) {
|
||||
return JSONConverter.jsonConvert(resultType, getByPath(expression), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putByPath(String expression, Object value) {
|
||||
public void putByPath(final String expression, final Object value) {
|
||||
BeanPath.create(expression).set(this, value);
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @throws JSONException 值是无穷数字抛出此异常
|
||||
*/
|
||||
@Override
|
||||
public Object put(String key, Object value) throws JSONException {
|
||||
public Object put(final String key, final Object value) throws JSONException {
|
||||
return put(key, value, null, false);
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return this.
|
||||
* @throws JSONException 值是无穷数字抛出此异常
|
||||
*/
|
||||
public JSONObject set(String key, Object value) throws JSONException {
|
||||
public JSONObject set(final String key, final Object value) throws JSONException {
|
||||
return set(key, value, null, false);
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @throws JSONException 值是无穷数字抛出此异常
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public JSONObject set(String key, Object value, Filter<MutablePair<String, Object>> filter, boolean checkDuplicate) throws JSONException {
|
||||
public JSONObject set(final String key, final Object value, final Filter<MutablePair<String, Object>> filter, final boolean checkDuplicate) throws JSONException {
|
||||
put(key, value, filter, checkDuplicate);
|
||||
return this;
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return this.
|
||||
* @throws JSONException 值是无穷数字、键重复抛出异常
|
||||
*/
|
||||
public JSONObject putOnce(String key, Object value) throws JSONException {
|
||||
public JSONObject putOnce(final String key, final Object value) throws JSONException {
|
||||
return setOnce(key, value, null);
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @throws JSONException 值是无穷数字、键重复抛出异常
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public JSONObject setOnce(String key, Object value, Filter<MutablePair<String, Object>> filter) throws JSONException {
|
||||
public JSONObject setOnce(final String key, final Object value, final Filter<MutablePair<String, Object>> filter) throws JSONException {
|
||||
return set(key, value, filter, true);
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return this.
|
||||
* @throws JSONException 值是无穷数字
|
||||
*/
|
||||
public JSONObject putOpt(String key, Object value) throws JSONException {
|
||||
public JSONObject putOpt(final String key, final Object value) throws JSONException {
|
||||
if (key != null && value != null) {
|
||||
this.set(key, value);
|
||||
}
|
||||
@@ -280,8 +280,8 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends String, ?> m) {
|
||||
for (Entry<? extends String, ?> entry : m.entrySet()) {
|
||||
public void putAll(final Map<? extends String, ?> m) {
|
||||
for (final Entry<? extends String, ?> entry : m.entrySet()) {
|
||||
this.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
@@ -295,9 +295,9 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return this.
|
||||
* @throws JSONException 如果给定键为{@code null}或者键对应的值存在且为非JSONArray
|
||||
*/
|
||||
public JSONObject accumulate(String key, Object value) throws JSONException {
|
||||
public JSONObject accumulate(final String key, final Object value) throws JSONException {
|
||||
InternalJSONUtil.testValidity(value);
|
||||
Object object = this.getObj(key);
|
||||
final Object object = this.getObj(key);
|
||||
if (object == null) {
|
||||
this.set(key, value);
|
||||
} else if (object instanceof JSONArray) {
|
||||
@@ -316,9 +316,9 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return this.
|
||||
* @throws JSONException 如果给定键为{@code null}或者键对应的值存在且为非JSONArray
|
||||
*/
|
||||
public JSONObject append(String key, Object value) throws JSONException {
|
||||
public JSONObject append(final String key, final Object value) throws JSONException {
|
||||
InternalJSONUtil.testValidity(value);
|
||||
Object object = this.getObj(key);
|
||||
final Object object = this.getObj(key);
|
||||
if (object == null) {
|
||||
this.set(key, new JSONArray(this.config).set(value));
|
||||
} else if (object instanceof JSONArray) {
|
||||
@@ -336,8 +336,8 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return this.
|
||||
* @throws JSONException 如果存在值非Integer, Long, Double, 或 Float.
|
||||
*/
|
||||
public JSONObject increment(String key) throws JSONException {
|
||||
Object value = this.getObj(key);
|
||||
public JSONObject increment(final String key) throws JSONException {
|
||||
final Object value = this.getObj(key);
|
||||
if (value == null) {
|
||||
this.set(key, 1);
|
||||
} else if (value instanceof BigInteger) {
|
||||
@@ -378,7 +378,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @return JSON字符串
|
||||
* @since 5.7.15
|
||||
*/
|
||||
public String toJSONString(int indentFactor, Filter<MutablePair<String, Object>> filter) {
|
||||
public String toJSONString(final int indentFactor, final Filter<MutablePair<String, Object>> filter) {
|
||||
final StringWriter sw = new StringWriter();
|
||||
synchronized (sw.getBuffer()) {
|
||||
return this.write(sw, indentFactor, 0, filter).toString();
|
||||
@@ -386,7 +386,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
|
||||
public Writer write(final Writer writer, final int indentFactor, final int indent) throws JSONException {
|
||||
return write(writer, indentFactor, indent, null);
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @throws JSONException JSON相关异常
|
||||
* @since 5.7.15
|
||||
*/
|
||||
public Writer write(Writer writer, int indentFactor, int indent, Filter<MutablePair<String, Object>> filter) throws JSONException {
|
||||
public Writer write(final Writer writer, final int indentFactor, final int indent, final Filter<MutablePair<String, Object>> filter) throws JSONException {
|
||||
final JSONWriter jsonWriter = JSONWriter.of(writer, indentFactor, indent, config)
|
||||
.beginObj();
|
||||
this.forEach((key, value) -> {
|
||||
@@ -439,7 +439,7 @@ public class JSONObject extends MapWrapper<String, Object> implements JSON, JSON
|
||||
* @throws JSONException 值是无穷数字抛出此异常
|
||||
* @since 5.8.0
|
||||
*/
|
||||
private Object put(String key, Object value, Filter<MutablePair<String, Object>> filter, boolean checkDuplicate) throws JSONException {
|
||||
private Object put(String key, Object value, final Filter<MutablePair<String, Object>> filter, final boolean checkDuplicate) throws JSONException {
|
||||
if (null == key) {
|
||||
return this;
|
||||
}
|
||||
|
@@ -4,15 +4,15 @@ import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* 此类用于在JSONAray中便于遍历JSONObject而封装的Iterable,可以借助foreach语法遍历
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.0.12
|
||||
*/
|
||||
public class JSONObjectIter implements Iterable<JSONObject> {
|
||||
|
||||
Iterator<Object> iterator;
|
||||
|
||||
public JSONObjectIter(Iterator<Object> iterator) {
|
||||
|
||||
public JSONObjectIter(final Iterator<Object> iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,7 @@ public class JSONParser {
|
||||
* @param tokener {@link JSONTokener}
|
||||
* @return JSONParser
|
||||
*/
|
||||
public static JSONParser of(JSONTokener tokener) {
|
||||
public static JSONParser of(final JSONTokener tokener) {
|
||||
return new JSONParser(tokener);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class JSONParser {
|
||||
*
|
||||
* @param tokener {@link JSONTokener}
|
||||
*/
|
||||
public JSONParser(JSONTokener tokener) {
|
||||
public JSONParser(final JSONTokener tokener) {
|
||||
this.tokener = tokener;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class JSONParser {
|
||||
* @param jsonObject {@link JSONObject}
|
||||
* @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对键值对的过滤和修改操作,{@code null}表示不过滤
|
||||
*/
|
||||
public void parseTo(JSONObject jsonObject, Filter<MutablePair<String, Object>> filter) {
|
||||
public void parseTo(final JSONObject jsonObject, final Filter<MutablePair<String, Object>> filter) {
|
||||
final JSONTokener tokener = this.tokener;
|
||||
|
||||
char c;
|
||||
@@ -95,7 +95,7 @@ public class JSONParser {
|
||||
* @param jsonArray {@link JSONArray}
|
||||
* @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,{@code null} 表示不过滤
|
||||
*/
|
||||
public void parseTo(JSONArray jsonArray, Filter<Mutable<Object>> filter) {
|
||||
public void parseTo(final JSONArray jsonArray, final Filter<Mutable<Object>> filter) {
|
||||
final JSONTokener x = this.tokener;
|
||||
|
||||
if (x.nextClean() != '[') {
|
||||
|
@@ -27,12 +27,12 @@ public class JSONStrFormatter {
|
||||
* @param json 未格式化的JSON字符串。
|
||||
* @return 格式化的JSON字符串。
|
||||
*/
|
||||
public static String format(String json) {
|
||||
public static String format(final String json) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
Character wrapChar = null;
|
||||
boolean isEscapeMode = false;
|
||||
int length = json.length();
|
||||
final int length = json.length();
|
||||
int number = 0;
|
||||
char key;
|
||||
for (int i = 0; i < length; i++) {
|
||||
@@ -134,7 +134,7 @@ public class JSONStrFormatter {
|
||||
* @param number 缩进次数。
|
||||
* @return 指定缩进次数的字符串。
|
||||
*/
|
||||
private static String indent(int number) {
|
||||
private static String indent(final int number) {
|
||||
return StrUtil.repeat(SPACE, number);
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ public class JSONSupport implements JSONString, JSONBeanParser<JSON> {
|
||||
*
|
||||
* @param jsonString JSON String
|
||||
*/
|
||||
public void parse(String jsonString) {
|
||||
public void parse(final String jsonString) {
|
||||
parse(new JSONObject(jsonString));
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class JSONSupport implements JSONString, JSONBeanParser<JSON> {
|
||||
* @param json JSON
|
||||
*/
|
||||
@Override
|
||||
public void parse(JSON json) {
|
||||
public void parse(final JSON json) {
|
||||
final JSONSupport support = JSONConverter.jsonToBean(getClass(), json, false);
|
||||
BeanUtil.copyProperties(support, this);
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ public class JSONTokener {
|
||||
* @param reader Reader
|
||||
* @param config JSON配置
|
||||
*/
|
||||
public JSONTokener(Reader reader, JSONConfig config) {
|
||||
public JSONTokener(final Reader reader, final JSONConfig config) {
|
||||
this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
|
||||
this.eof = false;
|
||||
this.usePrevious = false;
|
||||
@@ -72,7 +72,7 @@ public class JSONTokener {
|
||||
* @param inputStream InputStream
|
||||
* @param config JSON配置
|
||||
*/
|
||||
public JSONTokener(InputStream inputStream, JSONConfig config) throws JSONException {
|
||||
public JSONTokener(final InputStream inputStream, final JSONConfig config) throws JSONException {
|
||||
this(IoUtil.getUtf8Reader(inputStream), config);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class JSONTokener {
|
||||
* @param s JSON字符串
|
||||
* @param config JSON配置
|
||||
*/
|
||||
public JSONTokener(CharSequence s, JSONConfig config) {
|
||||
public JSONTokener(final CharSequence s, final JSONConfig config) {
|
||||
this(new StringReader(StrUtil.str(s)), config);
|
||||
}
|
||||
// ------------------------------------------------------------------------------------ Constructor end
|
||||
@@ -135,7 +135,7 @@ public class JSONTokener {
|
||||
} else {
|
||||
try {
|
||||
c = this.reader.read();
|
||||
} catch (IOException exception) {
|
||||
} catch (final IOException exception) {
|
||||
throw new JSONException(exception);
|
||||
}
|
||||
|
||||
@@ -165,8 +165,8 @@ public class JSONTokener {
|
||||
* @return The character 匹配到的字符
|
||||
* @throws JSONException 如果不匹配抛出此异常
|
||||
*/
|
||||
public char next(char c) throws JSONException {
|
||||
char n = this.next();
|
||||
public char next(final char c) throws JSONException {
|
||||
final char n = this.next();
|
||||
if (n != c) {
|
||||
throw this.syntaxError("Expected '" + c + "' and instead saw '" + n + "'");
|
||||
}
|
||||
@@ -180,12 +180,12 @@ public class JSONTokener {
|
||||
* @return 获得的n个字符组成的字符串
|
||||
* @throws JSONException 如果源中余下的字符数不足以提供所需的字符数,抛出此异常
|
||||
*/
|
||||
public String next(int n) throws JSONException {
|
||||
public String next(final int n) throws JSONException {
|
||||
if (n == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
char[] chars = new char[n];
|
||||
final char[] chars = new char[n];
|
||||
int pos = 0;
|
||||
while (pos < n) {
|
||||
chars[pos] = this.next();
|
||||
@@ -221,9 +221,9 @@ public class JSONTokener {
|
||||
* @return 截止到引号前的字符串
|
||||
* @throws JSONException 出现无结束的字符串时抛出此异常
|
||||
*/
|
||||
public String nextString(char quote) throws JSONException {
|
||||
public String nextString(final char quote) throws JSONException {
|
||||
char c;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
while (true) {
|
||||
c = this.next();
|
||||
switch (c) {
|
||||
@@ -278,10 +278,10 @@ public class JSONTokener {
|
||||
* @param delimiter 分隔符
|
||||
* @return 字符串
|
||||
*/
|
||||
public String nextTo(char delimiter) throws JSONException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
public String nextTo(final char delimiter) throws JSONException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (; ; ) {
|
||||
char c = this.next();
|
||||
final char c = this.next();
|
||||
if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
|
||||
if (c != 0) {
|
||||
this.back();
|
||||
@@ -298,9 +298,9 @@ public class JSONTokener {
|
||||
* @param delimiters A set of delimiter characters.
|
||||
* @return A string, trimmed.
|
||||
*/
|
||||
public String nextTo(String delimiters) throws JSONException {
|
||||
public String nextTo(final String delimiters) throws JSONException {
|
||||
char c;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (; ; ) {
|
||||
c = this.next();
|
||||
if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') {
|
||||
@@ -321,7 +321,7 @@ public class JSONTokener {
|
||||
*/
|
||||
public Object nextValue() throws JSONException {
|
||||
char c = this.nextClean();
|
||||
String string;
|
||||
final String string;
|
||||
|
||||
switch (c) {
|
||||
case '"':
|
||||
@@ -341,7 +341,7 @@ public class JSONTokener {
|
||||
* characters until we reach the end of the text or a formatting character.
|
||||
*/
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
|
||||
sb.append(c);
|
||||
c = this.next();
|
||||
@@ -361,12 +361,12 @@ public class JSONTokener {
|
||||
* @param to 需要定位的字符
|
||||
* @return 定位的字符,如果字符未找到返回0
|
||||
*/
|
||||
public char skipTo(char to) throws JSONException {
|
||||
public char skipTo(final char to) throws JSONException {
|
||||
char c;
|
||||
try {
|
||||
long startIndex = this.index;
|
||||
long startCharacter = this.character;
|
||||
long startLine = this.line;
|
||||
final long startIndex = this.index;
|
||||
final long startCharacter = this.character;
|
||||
final long startLine = this.line;
|
||||
this.reader.mark(1000000);
|
||||
do {
|
||||
c = this.next();
|
||||
@@ -378,7 +378,7 @@ public class JSONTokener {
|
||||
return c;
|
||||
}
|
||||
} while (c != to);
|
||||
} catch (IOException exception) {
|
||||
} catch (final IOException exception) {
|
||||
throw new JSONException(exception);
|
||||
}
|
||||
this.back();
|
||||
@@ -392,7 +392,7 @@ public class JSONTokener {
|
||||
* @param message 错误消息
|
||||
* @return A JSONException object, suitable for throwing
|
||||
*/
|
||||
public JSONException syntaxError(String message) {
|
||||
public JSONException syntaxError(final String message) {
|
||||
return new JSONException(message + this);
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ public class JSONTokener {
|
||||
* @return {@link JSONArray}
|
||||
*/
|
||||
public JSONArray toJSONArray() {
|
||||
JSONArray jsonArray = new JSONArray(this.config);
|
||||
final JSONArray jsonArray = new JSONArray(this.config);
|
||||
if (this.nextClean() != '[') {
|
||||
throw this.syntaxError("A JSONArray text must start with '['");
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ public class JSONUtil {
|
||||
* @return JSONObject
|
||||
* @since 5.2.5
|
||||
*/
|
||||
public static JSONObject createObj(JSONConfig config) {
|
||||
public static JSONObject createObj(final JSONConfig config) {
|
||||
return new JSONObject(config);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class JSONUtil {
|
||||
* @return JSONArray
|
||||
* @since 5.2.5
|
||||
*/
|
||||
public static JSONArray createArray(JSONConfig config) {
|
||||
public static JSONArray createArray(final JSONConfig config) {
|
||||
return new JSONArray(config);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class JSONUtil {
|
||||
* @param obj Bean对象或者Map
|
||||
* @return JSONObject
|
||||
*/
|
||||
public static JSONObject parseObj(Object obj) {
|
||||
public static JSONObject parseObj(final Object obj) {
|
||||
return new JSONObject(obj);
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class JSONUtil {
|
||||
* @return JSONObject
|
||||
* @since 5.3.1
|
||||
*/
|
||||
public static JSONObject parseObj(Object obj, JSONConfig config) {
|
||||
public static JSONObject parseObj(final Object obj, final JSONConfig config) {
|
||||
return new JSONObject(obj, config);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class JSONUtil {
|
||||
* @return JSONObject
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static JSONObject parseObj(Object obj, boolean ignoreNullValue) {
|
||||
public static JSONObject parseObj(final Object obj, final boolean ignoreNullValue) {
|
||||
return new JSONObject(obj, JSONConfig.create().setIgnoreNullValue(ignoreNullValue));
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class JSONUtil {
|
||||
* @return JSONArray
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public static JSONArray parseArray(Object arrayOrCollection) {
|
||||
public static JSONArray parseArray(final Object arrayOrCollection) {
|
||||
return new JSONArray(arrayOrCollection);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class JSONUtil {
|
||||
* @return JSONArray
|
||||
* @since 5.3.1
|
||||
*/
|
||||
public static JSONArray parseArray(Object arrayOrCollection, JSONConfig config) {
|
||||
public static JSONArray parseArray(final Object arrayOrCollection, final JSONConfig config) {
|
||||
return new JSONArray(arrayOrCollection, config);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class JSONUtil {
|
||||
* @return JSONArray
|
||||
* @since 3.2.3
|
||||
*/
|
||||
public static JSONArray parseArray(Object arrayOrCollection, boolean ignoreNullValue) {
|
||||
public static JSONArray parseArray(final Object arrayOrCollection, final boolean ignoreNullValue) {
|
||||
return new JSONArray(arrayOrCollection, JSONConfig.create().setIgnoreNullValue(ignoreNullValue));
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class JSONUtil {
|
||||
* @param obj 对象
|
||||
* @return JSON
|
||||
*/
|
||||
public static JSON parse(Object obj) {
|
||||
public static JSON parse(final Object obj) {
|
||||
return parse(obj, null);
|
||||
}
|
||||
|
||||
@@ -180,11 +180,11 @@ public class JSONUtil {
|
||||
* @return JSON
|
||||
* @since 5.3.1
|
||||
*/
|
||||
public static JSON parse(Object obj, JSONConfig config) {
|
||||
public static JSON parse(final Object obj, final JSONConfig config) {
|
||||
if (null == obj) {
|
||||
return null;
|
||||
}
|
||||
JSON json;
|
||||
final JSON json;
|
||||
if (obj instanceof JSON) {
|
||||
json = (JSON) obj;
|
||||
} else if (obj instanceof CharSequence) {
|
||||
@@ -208,7 +208,7 @@ public class JSONUtil {
|
||||
* @param xmlStr XML字符串
|
||||
* @return JSONObject
|
||||
*/
|
||||
public static JSONObject parseFromXml(String xmlStr) {
|
||||
public static JSONObject parseFromXml(final String xmlStr) {
|
||||
return XML.toJSONObject(xmlStr);
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ public class JSONUtil {
|
||||
* @return JSON(包括JSONObject和JSONArray)
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static JSON readJSON(File file, Charset charset) throws IORuntimeException {
|
||||
public static JSON readJSON(final File file, final Charset charset) throws IORuntimeException {
|
||||
return parse(FileReader.create(file, charset).readString());
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ public class JSONUtil {
|
||||
* @return JSONObject
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static JSONObject readJSONObject(File file, Charset charset) throws IORuntimeException {
|
||||
public static JSONObject readJSONObject(final File file, final Charset charset) throws IORuntimeException {
|
||||
return parseObj(FileReader.create(file, charset).readString());
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ public class JSONUtil {
|
||||
* @return JSONArray
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static JSONArray readJSONArray(File file, Charset charset) throws IORuntimeException {
|
||||
public static JSONArray readJSONArray(final File file, final Charset charset) throws IORuntimeException {
|
||||
return parseArray(FileReader.create(file, charset).readString());
|
||||
}
|
||||
// -------------------------------------------------------------------- Read end
|
||||
@@ -262,7 +262,7 @@ public class JSONUtil {
|
||||
* @param indentFactor 每一级别的缩进
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public static String toJsonStr(JSON json, int indentFactor) {
|
||||
public static String toJsonStr(final JSON json, final int indentFactor) {
|
||||
if (null == json) {
|
||||
return null;
|
||||
}
|
||||
@@ -275,7 +275,7 @@ public class JSONUtil {
|
||||
* @param json JSON
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public static String toJsonStr(JSON json) {
|
||||
public static String toJsonStr(final JSON json) {
|
||||
if (null == json) {
|
||||
return null;
|
||||
}
|
||||
@@ -289,7 +289,7 @@ public class JSONUtil {
|
||||
* @param writer Writer
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static void toJsonStr(JSON json, Writer writer) {
|
||||
public static void toJsonStr(final JSON json, final Writer writer) {
|
||||
if (null != json) {
|
||||
json.write(writer);
|
||||
}
|
||||
@@ -301,7 +301,7 @@ public class JSONUtil {
|
||||
* @param json JSON
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public static String toJsonPrettyStr(JSON json) {
|
||||
public static String toJsonPrettyStr(final JSON json) {
|
||||
if (null == json) {
|
||||
return null;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ public class JSONUtil {
|
||||
* @param obj 被转为JSON的对象
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public static String toJsonStr(Object obj) {
|
||||
public static String toJsonStr(final Object obj) {
|
||||
return toJsonStr(obj, (JSONConfig) null);
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ public class JSONUtil {
|
||||
* @return JSON字符串
|
||||
* @since 5.7.12
|
||||
*/
|
||||
public static String toJsonStr(Object obj, JSONConfig jsonConfig) {
|
||||
public static String toJsonStr(final Object obj, final JSONConfig jsonConfig) {
|
||||
if (null == obj) {
|
||||
return null;
|
||||
}
|
||||
@@ -343,7 +343,7 @@ public class JSONUtil {
|
||||
* @param writer Writer
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static void toJsonStr(Object obj, Writer writer) {
|
||||
public static void toJsonStr(final Object obj, final Writer writer) {
|
||||
if (null != obj) {
|
||||
toJsonStr(parse(obj), writer);
|
||||
}
|
||||
@@ -355,7 +355,7 @@ public class JSONUtil {
|
||||
* @param obj Bean对象
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public static String toJsonPrettyStr(Object obj) {
|
||||
public static String toJsonPrettyStr(final Object obj) {
|
||||
return toJsonPrettyStr(parse(obj));
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ public class JSONUtil {
|
||||
* @param json JSON
|
||||
* @return XML字符串
|
||||
*/
|
||||
public static String toXmlStr(JSON json) {
|
||||
public static String toXmlStr(final JSON json) {
|
||||
return XML.toXml(json);
|
||||
}
|
||||
// -------------------------------------------------------------------- toString end
|
||||
@@ -381,7 +381,7 @@ public class JSONUtil {
|
||||
* @return 实体类对象
|
||||
* @since 3.1.2
|
||||
*/
|
||||
public static <T> T toBean(String jsonString, Class<T> beanClass) {
|
||||
public static <T> T toBean(final String jsonString, final Class<T> beanClass) {
|
||||
return toBean(parseObj(jsonString), beanClass);
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ public class JSONUtil {
|
||||
* @return 实体类对象
|
||||
* @since 5.8.0
|
||||
*/
|
||||
public static <T> T toBean(String jsonString, JSONConfig config, Class<T> beanClass) {
|
||||
public static <T> T toBean(final String jsonString, final JSONConfig config, final Class<T> beanClass) {
|
||||
return toBean(parseObj(jsonString, config), beanClass);
|
||||
}
|
||||
|
||||
@@ -408,7 +408,7 @@ public class JSONUtil {
|
||||
* @param beanClass 实体类对象
|
||||
* @return 实体类对象
|
||||
*/
|
||||
public static <T> T toBean(JSONObject json, Class<T> beanClass) {
|
||||
public static <T> T toBean(final JSONObject json, final Class<T> beanClass) {
|
||||
return null == json ? null : json.toBean(beanClass);
|
||||
}
|
||||
|
||||
@@ -422,7 +422,7 @@ public class JSONUtil {
|
||||
* @return 实体类对象
|
||||
* @since 4.3.2
|
||||
*/
|
||||
public static <T> T toBean(String jsonString, TypeReference<T> typeReference, boolean ignoreError) {
|
||||
public static <T> T toBean(final String jsonString, final TypeReference<T> typeReference, final boolean ignoreError) {
|
||||
return toBean(jsonString, typeReference.getType(), ignoreError);
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ public class JSONUtil {
|
||||
* @return 实体类对象
|
||||
* @since 4.3.2
|
||||
*/
|
||||
public static <T> T toBean(String jsonString, Type beanType, boolean ignoreError) {
|
||||
public static <T> T toBean(final String jsonString, final Type beanType, final boolean ignoreError) {
|
||||
return parse(jsonString, JSONConfig.create().setIgnoreError(ignoreError)).toBean(beanType);
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ public class JSONUtil {
|
||||
* @return 实体类对象
|
||||
* @since 4.6.2
|
||||
*/
|
||||
public static <T> T toBean(JSON json, TypeReference<T> typeReference, boolean ignoreError) {
|
||||
public static <T> T toBean(final JSON json, final TypeReference<T> typeReference, final boolean ignoreError) {
|
||||
return toBean(json, typeReference.getType(), ignoreError);
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@ public class JSONUtil {
|
||||
* @return 实体类对象
|
||||
* @since 4.3.2
|
||||
*/
|
||||
public static <T> T toBean(JSON json, Type beanType, boolean ignoreError) {
|
||||
public static <T> T toBean(final JSON json, final Type beanType, final boolean ignoreError) {
|
||||
if (null == json) {
|
||||
return null;
|
||||
}
|
||||
@@ -481,7 +481,7 @@ public class JSONUtil {
|
||||
* @return List
|
||||
* @since 5.5.2
|
||||
*/
|
||||
public static <T> List<T> toList(String jsonArray, Class<T> elementType) {
|
||||
public static <T> List<T> toList(final String jsonArray, final Class<T> elementType) {
|
||||
return toList(parseArray(jsonArray), elementType);
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ public class JSONUtil {
|
||||
* @return List
|
||||
* @since 4.0.7
|
||||
*/
|
||||
public static <T> List<T> toList(JSONArray jsonArray, Class<T> elementType) {
|
||||
public static <T> List<T> toList(final JSONArray jsonArray, final Class<T> elementType) {
|
||||
return null == jsonArray ? null : jsonArray.toList(elementType);
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ public class JSONUtil {
|
||||
* @return 对象
|
||||
* @see JSON#getByPath(String)
|
||||
*/
|
||||
public static Object getByPath(JSON json, String expression) {
|
||||
public static Object getByPath(final JSON json, final String expression) {
|
||||
return getByPath(json, expression, null);
|
||||
}
|
||||
|
||||
@@ -548,7 +548,7 @@ public class JSONUtil {
|
||||
* @since 5.6.0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getByPath(JSON json, String expression, T defaultValue) {
|
||||
public static <T> T getByPath(final JSON json, final String expression, final T defaultValue) {
|
||||
if((null == json || StrUtil.isBlank(expression))){
|
||||
return defaultValue;
|
||||
}
|
||||
@@ -582,7 +582,7 @@ public class JSONUtil {
|
||||
* @param expression 表达式
|
||||
* @param value 值
|
||||
*/
|
||||
public static void putByPath(JSON json, String expression, Object value) {
|
||||
public static void putByPath(final JSON json, final String expression, final Object value) {
|
||||
json.putByPath(expression, value);
|
||||
}
|
||||
|
||||
@@ -594,7 +594,7 @@ public class JSONUtil {
|
||||
* @param string 字符串
|
||||
* @return 适合在JSON中显示的字符串
|
||||
*/
|
||||
public static String quote(String string) {
|
||||
public static String quote(final String string) {
|
||||
return quote(string, true);
|
||||
}
|
||||
|
||||
@@ -608,11 +608,11 @@ public class JSONUtil {
|
||||
* @return 适合在JSON中显示的字符串
|
||||
* @since 3.3.1
|
||||
*/
|
||||
public static String quote(String string, boolean isWrap) {
|
||||
StringWriter sw = new StringWriter();
|
||||
public static String quote(final String string, final boolean isWrap) {
|
||||
final StringWriter sw = new StringWriter();
|
||||
try {
|
||||
return quote(string, sw, isWrap).toString();
|
||||
} catch (IOException ignored) {
|
||||
} catch (final IOException ignored) {
|
||||
// will never happen - we are writing to a string writer
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
@@ -628,7 +628,7 @@ public class JSONUtil {
|
||||
* @return Writer
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public static Writer quote(String str, Writer writer) throws IOException {
|
||||
public static Writer quote(final String str, final Writer writer) throws IOException {
|
||||
return quote(str, writer, true);
|
||||
}
|
||||
|
||||
@@ -644,7 +644,7 @@ public class JSONUtil {
|
||||
* @throws IOException IO异常
|
||||
* @since 3.3.1
|
||||
*/
|
||||
public static Writer quote(String str, Writer writer, boolean isWrap) throws IOException {
|
||||
public static Writer quote(final String str, final Writer writer, final boolean isWrap) throws IOException {
|
||||
if (StrUtil.isEmpty(str)) {
|
||||
if (isWrap) {
|
||||
writer.write("\"\"");
|
||||
@@ -653,7 +653,7 @@ public class JSONUtil {
|
||||
}
|
||||
|
||||
char c; // 当前字符
|
||||
int len = str.length();
|
||||
final int len = str.length();
|
||||
if (isWrap) {
|
||||
writer.write('"');
|
||||
}
|
||||
@@ -681,7 +681,7 @@ public class JSONUtil {
|
||||
* @param str 字符串
|
||||
* @return 转义后的字符串
|
||||
*/
|
||||
public static String escape(String str) {
|
||||
public static String escape(final String str) {
|
||||
if (StrUtil.isEmpty(str)) {
|
||||
return str;
|
||||
}
|
||||
@@ -713,7 +713,7 @@ public class JSONUtil {
|
||||
* @return 包装后的值,null表示此值需被忽略
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static Object wrap(Object object, JSONConfig jsonConfig) {
|
||||
public static Object wrap(final Object object, final JSONConfig jsonConfig) {
|
||||
if (object == null) {
|
||||
return jsonConfig.isIgnoreNullValue() ? null : JSONNull.NULL;
|
||||
}
|
||||
@@ -774,7 +774,7 @@ public class JSONUtil {
|
||||
|
||||
// 默认按照JSONObject对待
|
||||
return new JSONObject(object, jsonConfig);
|
||||
} catch (Exception exception) {
|
||||
} catch (final Exception exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -786,7 +786,7 @@ public class JSONUtil {
|
||||
* @return 格式化后的字符串
|
||||
* @since 3.1.2
|
||||
*/
|
||||
public static String formatJsonStr(String jsonStr) {
|
||||
public static String formatJsonStr(final String jsonStr) {
|
||||
return JSONStrFormatter.format(jsonStr);
|
||||
}
|
||||
|
||||
@@ -797,7 +797,7 @@ public class JSONUtil {
|
||||
* @return 是否为JSON类型字符串
|
||||
* @since 5.7.22
|
||||
*/
|
||||
public static boolean isTypeJSON(String str) {
|
||||
public static boolean isTypeJSON(final String str) {
|
||||
return isTypeJSONObject(str) || isTypeJSONArray(str);
|
||||
}
|
||||
|
||||
@@ -808,7 +808,7 @@ public class JSONUtil {
|
||||
* @return 是否为JSON字符串
|
||||
* @since 5.7.22
|
||||
*/
|
||||
public static boolean isTypeJSONObject(String str) {
|
||||
public static boolean isTypeJSONObject(final String str) {
|
||||
if (StrUtil.isBlank(str)) {
|
||||
return false;
|
||||
}
|
||||
@@ -822,7 +822,7 @@ public class JSONUtil {
|
||||
* @return 是否为JSONArray类型字符串
|
||||
* @since 5.7.22
|
||||
*/
|
||||
public static boolean isTypeJSONArray(String str) {
|
||||
public static boolean isTypeJSONArray(final String str) {
|
||||
if (StrUtil.isBlank(str)) {
|
||||
return false;
|
||||
}
|
||||
@@ -841,7 +841,7 @@ public class JSONUtil {
|
||||
* @return 是否为null
|
||||
* @since 4.5.7
|
||||
*/
|
||||
public static boolean isNull(Object obj) {
|
||||
public static boolean isNull(final Object obj) {
|
||||
return null == obj || obj instanceof JSONNull;
|
||||
}
|
||||
|
||||
@@ -853,7 +853,7 @@ public class JSONUtil {
|
||||
* @return JSONObject
|
||||
* @since 4.0.8
|
||||
*/
|
||||
public static JSONObject xmlToJson(String xml) {
|
||||
public static JSONObject xmlToJson(final String xml) {
|
||||
return XML.toJSONObject(xml);
|
||||
}
|
||||
|
||||
@@ -865,7 +865,7 @@ public class JSONUtil {
|
||||
* @see GlobalSerializeMapping#put(Type, JSONArraySerializer)
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public static void putSerializer(Type type, JSONArraySerializer<?> serializer) {
|
||||
public static void putSerializer(final Type type, final JSONArraySerializer<?> serializer) {
|
||||
GlobalSerializeMapping.put(type, serializer);
|
||||
}
|
||||
|
||||
@@ -877,7 +877,7 @@ public class JSONUtil {
|
||||
* @see GlobalSerializeMapping#put(Type, JSONObjectSerializer)
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public static void putSerializer(Type type, JSONObjectSerializer<?> serializer) {
|
||||
public static void putSerializer(final Type type, final JSONObjectSerializer<?> serializer) {
|
||||
GlobalSerializeMapping.put(type, serializer);
|
||||
}
|
||||
|
||||
@@ -889,7 +889,7 @@ public class JSONUtil {
|
||||
* @see GlobalSerializeMapping#put(Type, JSONDeserializer)
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public static void putDeserializer(Type type, JSONDeserializer<?> deserializer) {
|
||||
public static void putDeserializer(final Type type, final JSONDeserializer<?> deserializer) {
|
||||
GlobalSerializeMapping.put(type, deserializer);
|
||||
}
|
||||
|
||||
@@ -902,7 +902,7 @@ public class JSONUtil {
|
||||
* @param c 字符
|
||||
* @return 转义后的字符串
|
||||
*/
|
||||
private static String escape(char c) {
|
||||
private static String escape(final char c) {
|
||||
switch (c) {
|
||||
case '\b':
|
||||
return "\\b";
|
||||
|
@@ -45,7 +45,7 @@ public class ObjectMapper {
|
||||
* @param source 来源对象
|
||||
* @return ObjectMapper
|
||||
*/
|
||||
public static ObjectMapper of(Object source) {
|
||||
public static ObjectMapper of(final Object source) {
|
||||
return new ObjectMapper(source);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ObjectMapper {
|
||||
*
|
||||
* @param source 来源对象
|
||||
*/
|
||||
public ObjectMapper(Object source) {
|
||||
public ObjectMapper(final Object source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class ObjectMapper {
|
||||
* @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对键值对的过滤和修改操作
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public void map(JSONObject jsonObject, Filter<MutablePair<String, Object>> filter) {
|
||||
public void map(final JSONObject jsonObject, final Filter<MutablePair<String, Object>> filter) {
|
||||
final Object source = this.source;
|
||||
if (null == source) {
|
||||
return;
|
||||
@@ -126,7 +126,7 @@ public class ObjectMapper {
|
||||
* @throws JSONException 非数组或集合
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public void map(JSONArray jsonArray, Filter<Mutable<Object>> filter) throws JSONException {
|
||||
public void map(final JSONArray jsonArray, final Filter<Mutable<Object>> filter) throws JSONException {
|
||||
final Object source = this.source;
|
||||
if (null == source) {
|
||||
return;
|
||||
@@ -148,7 +148,7 @@ public class ObjectMapper {
|
||||
} else if (source instanceof JSONTokener) {
|
||||
mapFromTokener((JSONTokener) source, jsonArray, filter);
|
||||
} else {
|
||||
Iterator<?> iter;
|
||||
final Iterator<?> iter;
|
||||
if (ArrayUtil.isArray(source)) {// 数组
|
||||
iter = new ArrayIter<>(source);
|
||||
} else if (source instanceof Iterator<?>) {// Iterator
|
||||
@@ -179,10 +179,10 @@ public class ObjectMapper {
|
||||
* @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对键值对的过滤和修改操作,{@code null}表示不过滤
|
||||
* @since 5.3.1
|
||||
*/
|
||||
private static void mapFromResourceBundle(ResourceBundle bundle, JSONObject jsonObject, Filter<MutablePair<String, Object>> filter) {
|
||||
Enumeration<String> keys = bundle.getKeys();
|
||||
private static void mapFromResourceBundle(final ResourceBundle bundle, final JSONObject jsonObject, final Filter<MutablePair<String, Object>> filter) {
|
||||
final Enumeration<String> keys = bundle.getKeys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = keys.nextElement();
|
||||
final String key = keys.nextElement();
|
||||
if (key != null) {
|
||||
InternalJSONUtil.propertyPut(jsonObject, key, bundle.getString(key), filter);
|
||||
}
|
||||
@@ -196,7 +196,7 @@ public class ObjectMapper {
|
||||
* @param jsonObject {@link JSONObject}
|
||||
* @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对键值对的过滤和修改操作,{@code null}表示不过滤
|
||||
*/
|
||||
private static void mapFromStr(CharSequence source, JSONObject jsonObject, Filter<MutablePair<String, Object>> filter) {
|
||||
private static void mapFromStr(final CharSequence source, final JSONObject jsonObject, final Filter<MutablePair<String, Object>> filter) {
|
||||
final String jsonStr = StrUtil.trim(source);
|
||||
if (StrUtil.startWith(jsonStr, '<')) {
|
||||
// 可能为XML
|
||||
@@ -213,7 +213,7 @@ public class ObjectMapper {
|
||||
* @param jsonArray {@link JSONArray}
|
||||
* @param filter 值过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,{@code null}表示不过滤
|
||||
*/
|
||||
private void mapFromStr(CharSequence source, JSONArray jsonArray, Filter<Mutable<Object>> filter) {
|
||||
private void mapFromStr(final CharSequence source, final JSONArray jsonArray, final Filter<Mutable<Object>> filter) {
|
||||
if (null != source) {
|
||||
mapFromTokener(new JSONTokener(StrUtil.trim(source), jsonArray.getConfig()), jsonArray, filter);
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public class ObjectMapper {
|
||||
* @param jsonObject {@link JSONObject}
|
||||
* @param filter 键值对过滤编辑器,可以通过实现此接口,完成解析前对键值对的过滤和修改操作
|
||||
*/
|
||||
private static void mapFromTokener(JSONTokener x, JSONObject jsonObject, Filter<MutablePair<String, Object>> filter) {
|
||||
private static void mapFromTokener(final JSONTokener x, final JSONObject jsonObject, final Filter<MutablePair<String, Object>> filter) {
|
||||
JSONParser.of(x).parseTo(jsonObject, filter);
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public class ObjectMapper {
|
||||
* @param jsonArray {@link JSONArray}
|
||||
* @param filter 值过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,{@code null}表示不过滤
|
||||
*/
|
||||
private static void mapFromTokener(JSONTokener x, JSONArray jsonArray, Filter<Mutable<Object>> filter) {
|
||||
private static void mapFromTokener(final JSONTokener x, final JSONArray jsonArray, final Filter<Mutable<Object>> filter) {
|
||||
JSONParser.of(x).parseTo(jsonArray, filter);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ public class ObjectMapper {
|
||||
* @param bean Bean对象
|
||||
* @param jsonObject {@link JSONObject}
|
||||
*/
|
||||
private static void mapFromBean(Object bean, JSONObject jsonObject) {
|
||||
private static void mapFromBean(final Object bean, final JSONObject jsonObject) {
|
||||
BeanUtil.beanToMap(bean, jsonObject, InternalJSONUtil.toCopyOptions(jsonObject.getConfig()));
|
||||
}
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ public class XML {
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
* @throws JSONException Thrown if there is an errors while parsing the string
|
||||
*/
|
||||
public static JSONObject toJSONObject(String string) throws JSONException {
|
||||
public static JSONObject toJSONObject(final String string) throws JSONException {
|
||||
return toJSONObject(string, false);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class XML {
|
||||
* @return A JSONObject containing the structured data from the XML string.
|
||||
* @throws JSONException Thrown if there is an errors while parsing the string
|
||||
*/
|
||||
public static JSONObject toJSONObject(String string, boolean keepStrings) throws JSONException {
|
||||
public static JSONObject toJSONObject(final String string, final boolean keepStrings) throws JSONException {
|
||||
return toJSONObject(new JSONObject(), string, keepStrings);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class XML {
|
||||
* @throws JSONException 解析异常
|
||||
* @since 5.3.1
|
||||
*/
|
||||
public static JSONObject toJSONObject(JSONObject jo, String xmlStr, boolean keepStrings) throws JSONException {
|
||||
public static JSONObject toJSONObject(final JSONObject jo, final String xmlStr, final boolean keepStrings) throws JSONException {
|
||||
JSONXMLParser.parseJSONObject(jo, xmlStr, keepStrings);
|
||||
return jo;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class XML {
|
||||
* @return XML字符串
|
||||
* @throws JSONException JSON解析异常
|
||||
*/
|
||||
public static String toXml(Object object) throws JSONException {
|
||||
public static String toXml(final Object object) throws JSONException {
|
||||
return toXml(object, null);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class XML {
|
||||
* @return A string.
|
||||
* @throws JSONException JSON解析异常
|
||||
*/
|
||||
public static String toXml(Object object, String tagName) throws JSONException {
|
||||
public static String toXml(final Object object, final String tagName) throws JSONException {
|
||||
return toXml(object, tagName, "content");
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class XML {
|
||||
* @return A string.
|
||||
* @throws JSONException JSON解析异常
|
||||
*/
|
||||
public static String toXml(Object object, String tagName, String... contentKeys) throws JSONException {
|
||||
public static String toXml(final Object object, final String tagName, final String... contentKeys) throws JSONException {
|
||||
return JSONXMLSerializer.toXml(object, tagName, contentKeys);
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ public class XMLTokener extends JSONTokener {
|
||||
* @param s A source string.
|
||||
* @param config JSON配置
|
||||
*/
|
||||
public XMLTokener(CharSequence s, JSONConfig config) {
|
||||
public XMLTokener(final CharSequence s, final JSONConfig config) {
|
||||
super(s, config);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class XMLTokener extends JSONTokener {
|
||||
public String nextCDATA() throws JSONException {
|
||||
char c;
|
||||
int i;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (; ; ) {
|
||||
c = next();
|
||||
if (end()) {
|
||||
@@ -65,7 +65,7 @@ public class XMLTokener extends JSONTokener {
|
||||
*/
|
||||
public Object nextContent() throws JSONException {
|
||||
char c;
|
||||
StringBuilder sb;
|
||||
final StringBuilder sb;
|
||||
do {
|
||||
c = next();
|
||||
} while (Character.isWhitespace(c));
|
||||
@@ -97,10 +97,10 @@ public class XMLTokener extends JSONTokener {
|
||||
* @return A Character or an entity String if the entity is not recognized.
|
||||
* @throws JSONException If missing ';' in XML entity.
|
||||
*/
|
||||
public Object nextEntity(char ampersand) throws JSONException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
public Object nextEntity(final char ampersand) throws JSONException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (; ; ) {
|
||||
char c = next();
|
||||
final char c = next();
|
||||
if (Character.isLetterOrDigit(c) || c == '#') {
|
||||
sb.append(Character.toLowerCase(c));
|
||||
} else if (c == ';') {
|
||||
@@ -109,8 +109,8 @@ public class XMLTokener extends JSONTokener {
|
||||
throw syntaxError("Missing ';' in XML entity: &" + sb);
|
||||
}
|
||||
}
|
||||
String string = sb.toString();
|
||||
Object object = entity.get(string);
|
||||
final String string = sb.toString();
|
||||
final Object object = entity.get(string);
|
||||
return object != null ? object : ampersand + string + ";";
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class XMLTokener extends JSONTokener {
|
||||
*/
|
||||
public Object nextMeta() throws JSONException {
|
||||
char c;
|
||||
char q;
|
||||
final char q;
|
||||
do {
|
||||
c = next();
|
||||
} while (Character.isWhitespace(c));
|
||||
@@ -186,8 +186,8 @@ public class XMLTokener extends JSONTokener {
|
||||
*/
|
||||
public Object nextToken() throws JSONException {
|
||||
char c;
|
||||
char q;
|
||||
StringBuilder sb;
|
||||
final char q;
|
||||
final StringBuilder sb;
|
||||
do {
|
||||
c = next();
|
||||
} while (Character.isWhitespace(c));
|
||||
@@ -266,14 +266,14 @@ public class XMLTokener extends JSONTokener {
|
||||
* @return 是否成功skip
|
||||
* @throws JSONException JSON异常
|
||||
*/
|
||||
public boolean skipPast(String to) throws JSONException {
|
||||
public boolean skipPast(final String to) throws JSONException {
|
||||
boolean b;
|
||||
char c;
|
||||
int i;
|
||||
int j;
|
||||
int offset = 0;
|
||||
int length = to.length();
|
||||
char[] circle = new char[length];
|
||||
final int length = to.length();
|
||||
final char[] circle = new char[length];
|
||||
|
||||
/*
|
||||
* First fill the circle buffer with as many characters as are in the to string. If we reach an early end, bail.
|
||||
|
@@ -31,7 +31,7 @@ public class Claims implements Serializable {
|
||||
* @param name 属性名
|
||||
* @param value 属性值
|
||||
*/
|
||||
protected void setClaim(String name, Object value) {
|
||||
protected void setClaim(final String name, final Object value) {
|
||||
init();
|
||||
Assert.notNull(name, "Name must be not null!");
|
||||
if (value == null) {
|
||||
@@ -45,9 +45,9 @@ public class Claims implements Serializable {
|
||||
* 加入多个Claims属性
|
||||
* @param headerClaims 多个Claims属性
|
||||
*/
|
||||
protected void putAll(Map<String, ?> headerClaims){
|
||||
protected void putAll(final Map<String, ?> headerClaims){
|
||||
if (MapUtil.isNotEmpty(headerClaims)) {
|
||||
for (Map.Entry<String, ?> entry : headerClaims.entrySet()) {
|
||||
for (final Map.Entry<String, ?> entry : headerClaims.entrySet()) {
|
||||
setClaim(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class Claims implements Serializable {
|
||||
* @param name 名称
|
||||
* @return 属性
|
||||
*/
|
||||
public Object getClaim(String name) {
|
||||
public Object getClaim(final String name) {
|
||||
init();
|
||||
return this.claimJSON.getObj(name);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class Claims implements Serializable {
|
||||
* @param tokenPart JWT JSON
|
||||
* @param charset 编码
|
||||
*/
|
||||
public void parse(String tokenPart, Charset charset) {
|
||||
public void parse(final String tokenPart, final Charset charset) {
|
||||
this.claimJSON = JSONUtil.parseObj(Base64.decodeStr(tokenPart, charset), CONFIG);
|
||||
}
|
||||
|
||||
|
@@ -62,7 +62,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param token JWT Token字符串,格式为xxxx.yyyy.zzzz
|
||||
* @return JWT
|
||||
*/
|
||||
public static JWT of(String token) {
|
||||
public static JWT of(final String token) {
|
||||
return new JWT(token);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
*
|
||||
* @param token JWT Token字符串,格式为xxxx.yyyy.zzzz
|
||||
*/
|
||||
public JWT(String token) {
|
||||
public JWT(final String token) {
|
||||
this();
|
||||
parse(token);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param token JWT Token字符串,格式为xxxx.yyyy.zzzz
|
||||
* @return this
|
||||
*/
|
||||
public JWT parse(String token) {
|
||||
public JWT parse(final String token) {
|
||||
final List<String> tokens = splitToken(token);
|
||||
this.tokens = tokens;
|
||||
this.header.parse(tokens.get(0), this.charset);
|
||||
@@ -105,7 +105,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param charset 编码
|
||||
* @return this
|
||||
*/
|
||||
public JWT setCharset(Charset charset) {
|
||||
public JWT setCharset(final Charset charset) {
|
||||
this.charset = charset;
|
||||
return this;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param key 密钥
|
||||
* @return this
|
||||
*/
|
||||
public JWT setKey(byte[] key) {
|
||||
public JWT setKey(final byte[] key) {
|
||||
return setSigner(JWTSignerUtil.hs256(key));
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param key 密钥
|
||||
* @return this
|
||||
*/
|
||||
public JWT setSigner(String algorithmId, byte[] key) {
|
||||
public JWT setSigner(final String algorithmId, final byte[] key) {
|
||||
return setSigner(JWTSignerUtil.createSigner(algorithmId, key));
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @return this
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public JWT setSigner(String algorithmId, Key key) {
|
||||
public JWT setSigner(final String algorithmId, final Key key) {
|
||||
return setSigner(JWTSignerUtil.createSigner(algorithmId, key));
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @return this
|
||||
* @since 5.7.2
|
||||
*/
|
||||
public JWT setSigner(String algorithmId, KeyPair keyPair) {
|
||||
public JWT setSigner(final String algorithmId, final KeyPair keyPair) {
|
||||
return setSigner(JWTSignerUtil.createSigner(algorithmId, keyPair));
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param signer 签名算法
|
||||
* @return this
|
||||
*/
|
||||
public JWT setSigner(JWTSigner signer) {
|
||||
public JWT setSigner(final JWTSigner signer) {
|
||||
this.signer = signer;
|
||||
return this;
|
||||
}
|
||||
@@ -200,7 +200,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param name 头信息名称
|
||||
* @return 头信息
|
||||
*/
|
||||
public Object getHeader(String name) {
|
||||
public Object getHeader(final String name) {
|
||||
return this.header.getClaim(name);
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param value 头
|
||||
* @return this
|
||||
*/
|
||||
public JWT setHeader(String name, Object value) {
|
||||
public JWT setHeader(final String name, final Object value) {
|
||||
this.header.setClaim(name, value);
|
||||
return this;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param headers 头信息
|
||||
* @return this
|
||||
*/
|
||||
public JWT addHeaders(Map<String, ?> headers) {
|
||||
public JWT addHeaders(final Map<String, ?> headers) {
|
||||
this.header.addHeaders(headers);
|
||||
return this;
|
||||
}
|
||||
@@ -262,7 +262,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param name 载荷信息名称
|
||||
* @return 载荷信息
|
||||
*/
|
||||
public Object getPayload(String name) {
|
||||
public Object getPayload(final String name) {
|
||||
return getPayload().getClaim(name);
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public JWT setPayload(String name, Object value) {
|
||||
public JWT setPayload(final String name, final Object value) {
|
||||
this.payload.setClaim(name, value);
|
||||
return this;
|
||||
}
|
||||
@@ -285,7 +285,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param payloads 载荷信息
|
||||
* @return this
|
||||
*/
|
||||
public JWT addPayloads(Map<String, ?> payloads) {
|
||||
public JWT addPayloads(final Map<String, ?> payloads) {
|
||||
this.payload.addPayloads(payloads);
|
||||
return this;
|
||||
}
|
||||
@@ -305,7 +305,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param signer JWT签名器
|
||||
* @return JWT字符串
|
||||
*/
|
||||
public String sign(JWTSigner signer) {
|
||||
public String sign(final JWTSigner signer) {
|
||||
Assert.notNull(signer, () -> new JWTException("No Signer provided!"));
|
||||
|
||||
// 检查头信息中是否有算法信息
|
||||
@@ -346,7 +346,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @see JWTValidator
|
||||
* @since 5.7.4
|
||||
*/
|
||||
public boolean validate(long leeway) {
|
||||
public boolean validate(final long leeway) {
|
||||
if (false == verify()) {
|
||||
return false;
|
||||
}
|
||||
@@ -354,7 +354,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
// 校验时间字段
|
||||
try {
|
||||
JWTValidator.of(this).validateDate(DateUtil.date(), leeway);
|
||||
} catch (ValidateException e) {
|
||||
} catch (final ValidateException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -386,7 +386,7 @@ public class JWT implements RegisteredPayload<JWT> {
|
||||
* @param token JWT Token
|
||||
* @return 三部分内容
|
||||
*/
|
||||
private static List<String> splitToken(String token) {
|
||||
private static List<String> splitToken(final String token) {
|
||||
final List<String> tokens = StrUtil.split(token, CharUtil.DOT);
|
||||
if (3 != tokens.size()) {
|
||||
throw new JWTException("The token was expected 3 parts, but got {}.", tokens.size());
|
||||
|
@@ -12,27 +12,27 @@ import cn.hutool.core.text.StrUtil;
|
||||
public class JWTException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public JWTException(Throwable e) {
|
||||
public JWTException(final Throwable e) {
|
||||
super(ExceptionUtil.getMessage(e), e);
|
||||
}
|
||||
|
||||
public JWTException(String message) {
|
||||
public JWTException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JWTException(String messageTemplate, Object... params) {
|
||||
public JWTException(final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params));
|
||||
}
|
||||
|
||||
public JWTException(String message, Throwable cause) {
|
||||
public JWTException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JWTException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) {
|
||||
public JWTException(final String message, final Throwable throwable, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||
super(message, throwable, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public JWTException(Throwable throwable, String messageTemplate, Object... params) {
|
||||
public JWTException(final Throwable throwable, final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params), throwable);
|
||||
}
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ public class JWTHeader extends Claims {
|
||||
* @param keyId kid
|
||||
* @return this
|
||||
*/
|
||||
public JWTHeader setKeyId(String keyId) {
|
||||
public JWTHeader setKeyId(final String keyId) {
|
||||
setClaim(KEY_ID, keyId);
|
||||
return this;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class JWTHeader extends Claims {
|
||||
* @param headerClaims 头信息
|
||||
* @return this
|
||||
*/
|
||||
public JWTHeader addHeaders(Map<String, ?> headerClaims) {
|
||||
public JWTHeader addHeaders(final Map<String, ?> headerClaims) {
|
||||
putAll(headerClaims);
|
||||
return this;
|
||||
}
|
||||
|
@@ -26,13 +26,13 @@ public class JWTPayload extends Claims implements RegisteredPayload<JWTPayload>{
|
||||
* @param payloadClaims 载荷信息
|
||||
* @return this
|
||||
*/
|
||||
public JWTPayload addPayloads(Map<String, ?> payloadClaims) {
|
||||
public JWTPayload addPayloads(final Map<String, ?> payloadClaims) {
|
||||
putAll(payloadClaims);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JWTPayload setPayload(String name, Object value) {
|
||||
public JWTPayload setPayload(final String name, final Object value) {
|
||||
setClaim(name, value);
|
||||
return this;
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ public class JWTUtil {
|
||||
* @param key HS256(HmacSHA256)密钥
|
||||
* @return JWT Token
|
||||
*/
|
||||
public static String createToken(Map<String, Object> payload, byte[] key) {
|
||||
public static String createToken(final Map<String, Object> payload, final byte[] key) {
|
||||
return createToken(null, payload, key);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class JWTUtil {
|
||||
* @param key HS256(HmacSHA256)密钥
|
||||
* @return JWT Token
|
||||
*/
|
||||
public static String createToken(Map<String, Object> headers, Map<String, Object> payload, byte[] key) {
|
||||
public static String createToken(final Map<String, Object> headers, final Map<String, Object> payload, final byte[] key) {
|
||||
return JWT.create()
|
||||
.addHeaders(headers)
|
||||
.addPayloads(payload)
|
||||
@@ -43,7 +43,7 @@ public class JWTUtil {
|
||||
* @param signer 签名算法
|
||||
* @return JWT Token
|
||||
*/
|
||||
public static String createToken(Map<String, Object> payload, JWTSigner signer) {
|
||||
public static String createToken(final Map<String, Object> payload, final JWTSigner signer) {
|
||||
return createToken(null, payload, signer);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class JWTUtil {
|
||||
* @param signer 签名算法
|
||||
* @return JWT Token
|
||||
*/
|
||||
public static String createToken(Map<String, Object> headers, Map<String, Object> payload, JWTSigner signer) {
|
||||
public static String createToken(final Map<String, Object> headers, final Map<String, Object> payload, final JWTSigner signer) {
|
||||
return JWT.create()
|
||||
.addHeaders(headers)
|
||||
.addPayloads(payload)
|
||||
@@ -69,7 +69,7 @@ public class JWTUtil {
|
||||
* @param token token
|
||||
* @return {@link JWT}
|
||||
*/
|
||||
public static JWT parseToken(String token) {
|
||||
public static JWT parseToken(final String token) {
|
||||
return JWT.of(token);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class JWTUtil {
|
||||
* @param key HS256(HmacSHA256)密钥
|
||||
* @return 是否有效
|
||||
*/
|
||||
public static boolean verify(String token, byte[] key) {
|
||||
public static boolean verify(final String token, final byte[] key) {
|
||||
return JWT.of(token).setKey(key).verify();
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class JWTUtil {
|
||||
* @param signer 签名器
|
||||
* @return 是否有效
|
||||
*/
|
||||
public static boolean verify(String token, JWTSigner signer) {
|
||||
public static boolean verify(final String token, final JWTSigner signer) {
|
||||
return JWT.of(token).verify(signer);
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ public class JWTValidator {
|
||||
* @param token JWT Token
|
||||
* @return JWTValidator
|
||||
*/
|
||||
public static JWTValidator of(String token) {
|
||||
public static JWTValidator of(final String token) {
|
||||
return new JWTValidator(JWT.of(token));
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class JWTValidator {
|
||||
* @param jwt JWT对象
|
||||
* @return JWTValidator
|
||||
*/
|
||||
public static JWTValidator of(JWT jwt) {
|
||||
public static JWTValidator of(final JWT jwt) {
|
||||
return new JWTValidator(jwt);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JWTValidator {
|
||||
*
|
||||
* @param jwt JWT对象
|
||||
*/
|
||||
public JWTValidator(JWT jwt) {
|
||||
public JWTValidator(final JWT jwt) {
|
||||
this.jwt = jwt;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class JWTValidator {
|
||||
* @return this
|
||||
* @throws ValidateException 验证失败的异常
|
||||
*/
|
||||
public JWTValidator validateAlgorithm(JWTSigner signer) throws ValidateException {
|
||||
public JWTValidator validateAlgorithm(final JWTSigner signer) throws ValidateException {
|
||||
validateAlgorithm(this.jwt, signer);
|
||||
return this;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class JWTValidator {
|
||||
* @return this
|
||||
* @throws ValidateException 验证失败的异常
|
||||
*/
|
||||
public JWTValidator validateDate(Date dateToCheck) throws ValidateException {
|
||||
public JWTValidator validateDate(final Date dateToCheck) throws ValidateException {
|
||||
validateDate(this.jwt.getPayload(), dateToCheck, 0L);
|
||||
return this;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public class JWTValidator {
|
||||
* @return this
|
||||
* @throws ValidateException 验证失败的异常
|
||||
*/
|
||||
public JWTValidator validateDate(Date dateToCheck, long leeway) throws ValidateException {
|
||||
public JWTValidator validateDate(final Date dateToCheck, final long leeway) throws ValidateException {
|
||||
validateDate(this.jwt.getPayload(), dateToCheck, leeway);
|
||||
return this;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public class JWTValidator {
|
||||
* @param signer 用于验证的签名器
|
||||
* @throws ValidateException 验证异常
|
||||
*/
|
||||
private static void validateAlgorithm(JWT jwt, JWTSigner signer) throws ValidateException {
|
||||
private static void validateAlgorithm(final JWT jwt, JWTSigner signer) throws ValidateException {
|
||||
final String algorithmId = jwt.getAlgorithm();
|
||||
if (null == signer) {
|
||||
signer = jwt.getSigner();
|
||||
@@ -187,7 +187,7 @@ public class JWTValidator {
|
||||
* @param leeway 容忍空间,单位:秒。当不能晚于当前时间时,向后容忍;不能早于向前容忍。
|
||||
* @throws ValidateException 验证异常
|
||||
*/
|
||||
private static void validateDate(JWTPayload payload, Date now, long leeway) throws ValidateException {
|
||||
private static void validateDate(final JWTPayload payload, Date now, final long leeway) throws ValidateException {
|
||||
if (null == now) {
|
||||
// 默认当前时间
|
||||
now = DateUtil.date();
|
||||
@@ -218,7 +218,7 @@ public class JWTValidator {
|
||||
* @param leeway 容忍空间,单位:秒。向后容忍
|
||||
* @throws ValidateException 验证异常
|
||||
*/
|
||||
private static void validateNotAfter(String fieldName, Date dateToCheck, Date now, long leeway) throws ValidateException {
|
||||
private static void validateNotAfter(final String fieldName, final Date dateToCheck, final Date now, final long leeway) throws ValidateException {
|
||||
if (null == dateToCheck) {
|
||||
return;
|
||||
}
|
||||
@@ -240,7 +240,7 @@ public class JWTValidator {
|
||||
* @throws ValidateException 验证异常
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private static void validateNotBefore(String fieldName, Date dateToCheck, Date now, long leeway) throws ValidateException {
|
||||
private static void validateNotBefore(final String fieldName, final Date dateToCheck, final Date now, final long leeway) throws ValidateException {
|
||||
if (null == dateToCheck) {
|
||||
return;
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ public interface RegisteredPayload<T extends RegisteredPayload<T>> {
|
||||
* @param issuer jwt签发者
|
||||
* @return this
|
||||
*/
|
||||
default T setIssuer(String issuer) {
|
||||
default T setIssuer(final String issuer) {
|
||||
return setPayload(ISSUER, issuer);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public interface RegisteredPayload<T extends RegisteredPayload<T>> {
|
||||
* @param subject jwt所面向的用户
|
||||
* @return this
|
||||
*/
|
||||
default T setSubject(String subject) {
|
||||
default T setSubject(final String subject) {
|
||||
return setPayload(SUBJECT, subject);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public interface RegisteredPayload<T extends RegisteredPayload<T>> {
|
||||
* @param audience 接收jwt的一方
|
||||
* @return this
|
||||
*/
|
||||
default T setAudience(String... audience) {
|
||||
default T setAudience(final String... audience) {
|
||||
return setPayload(AUDIENCE, audience);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public interface RegisteredPayload<T extends RegisteredPayload<T>> {
|
||||
* @return this
|
||||
* @see #setIssuedAt(Date)
|
||||
*/
|
||||
default T setExpiresAt(Date expiresAt) {
|
||||
default T setExpiresAt(final Date expiresAt) {
|
||||
return setPayload(EXPIRES_AT, expiresAt);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public interface RegisteredPayload<T extends RegisteredPayload<T>> {
|
||||
* @param notBefore 不可用时间点界限,在这个时间点之前,jwt不可用
|
||||
* @return this
|
||||
*/
|
||||
default T setNotBefore(Date notBefore) {
|
||||
default T setNotBefore(final Date notBefore) {
|
||||
return setPayload(NOT_BEFORE, notBefore);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public interface RegisteredPayload<T extends RegisteredPayload<T>> {
|
||||
* @param issuedAt 签发时间
|
||||
* @return this
|
||||
*/
|
||||
default T setIssuedAt(Date issuedAt) {
|
||||
default T setIssuedAt(final Date issuedAt) {
|
||||
return setPayload(ISSUED_AT, issuedAt);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public interface RegisteredPayload<T extends RegisteredPayload<T>> {
|
||||
* @param jwtId 唯一身份标识
|
||||
* @return this
|
||||
*/
|
||||
default T setJWTId(String jwtId) {
|
||||
default T setJWTId(final String jwtId) {
|
||||
return setPayload(JWT_ID, jwtId);
|
||||
}
|
||||
|
||||
|
@@ -41,7 +41,7 @@ public class AlgorithmUtil {
|
||||
* @param idOrAlgorithm 算法ID或算法名
|
||||
* @return 算法名
|
||||
*/
|
||||
public static String getAlgorithm(String idOrAlgorithm){
|
||||
public static String getAlgorithm(final String idOrAlgorithm){
|
||||
return ObjUtil.defaultIfNull(getAlgorithmById(idOrAlgorithm), idOrAlgorithm);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AlgorithmUtil {
|
||||
* @param idOrAlgorithm 算法ID或算法名
|
||||
* @return 算法ID
|
||||
*/
|
||||
public static String getId(String idOrAlgorithm){
|
||||
public static String getId(final String idOrAlgorithm){
|
||||
return ObjUtil.defaultIfNull(getIdByAlgorithm(idOrAlgorithm), idOrAlgorithm);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class AlgorithmUtil {
|
||||
* @param id JWT算法ID
|
||||
* @return 算法
|
||||
*/
|
||||
private static String getAlgorithmById(String id) {
|
||||
private static String getAlgorithmById(final String id) {
|
||||
return map.get(id.toUpperCase());
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class AlgorithmUtil {
|
||||
* @param algorithm 算法
|
||||
* @return JWT算法ID
|
||||
*/
|
||||
private static String getIdByAlgorithm(String algorithm) {
|
||||
private static String getIdByAlgorithm(final String algorithm) {
|
||||
return map.getKey(algorithm);
|
||||
}
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ public class AsymmetricJWTSigner implements JWTSigner {
|
||||
* @param algorithm 算法字符串表示
|
||||
* @param key 公钥{@link PublicKey}或私钥{@link PrivateKey},公钥用于验证签名,私钥用于产生签名
|
||||
*/
|
||||
public AsymmetricJWTSigner(String algorithm, Key key) {
|
||||
public AsymmetricJWTSigner(final String algorithm, final Key key) {
|
||||
final PublicKey publicKey = key instanceof PublicKey ? (PublicKey) key : null;
|
||||
final PrivateKey privateKey = key instanceof PrivateKey ? (PrivateKey) key : null;
|
||||
this.sign = new Sign(algorithm, privateKey, publicKey);
|
||||
@@ -40,7 +40,7 @@ public class AsymmetricJWTSigner implements JWTSigner {
|
||||
* @param algorithm 算法字符串表示
|
||||
* @param keyPair 密钥对
|
||||
*/
|
||||
public AsymmetricJWTSigner(String algorithm, KeyPair keyPair) {
|
||||
public AsymmetricJWTSigner(final String algorithm, final KeyPair keyPair) {
|
||||
this.sign = new Sign(algorithm, keyPair);
|
||||
}
|
||||
|
||||
@@ -50,18 +50,18 @@ public class AsymmetricJWTSigner implements JWTSigner {
|
||||
* @param charset 编码
|
||||
* @return 编码
|
||||
*/
|
||||
public AsymmetricJWTSigner setCharset(Charset charset) {
|
||||
public AsymmetricJWTSigner setCharset(final Charset charset) {
|
||||
this.charset = charset;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sign(String headerBase64, String payloadBase64) {
|
||||
public String sign(final String headerBase64, final String payloadBase64) {
|
||||
return Base64.encodeUrlSafe(sign.sign(StrUtil.format("{}.{}", headerBase64, payloadBase64)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String headerBase64, String payloadBase64, String signBase64) {
|
||||
public boolean verify(final String headerBase64, final String payloadBase64, final String signBase64) {
|
||||
return sign.verify(
|
||||
StrUtil.bytes(StrUtil.format("{}.{}", headerBase64, payloadBase64), charset),
|
||||
Base64.decode(signBase64));
|
||||
|
@@ -24,7 +24,7 @@ public class HMacJWTSigner implements JWTSigner {
|
||||
* @param algorithm HMAC签名算法
|
||||
* @param key 密钥
|
||||
*/
|
||||
public HMacJWTSigner(String algorithm, byte[] key) {
|
||||
public HMacJWTSigner(final String algorithm, final byte[] key) {
|
||||
this.hMac = new HMac(algorithm, key);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class HMacJWTSigner implements JWTSigner {
|
||||
* @param algorithm HMAC签名算法
|
||||
* @param key 密钥
|
||||
*/
|
||||
public HMacJWTSigner(String algorithm, Key key) {
|
||||
public HMacJWTSigner(final String algorithm, final Key key) {
|
||||
this.hMac = new HMac(algorithm, key);
|
||||
}
|
||||
|
||||
@@ -44,18 +44,18 @@ public class HMacJWTSigner implements JWTSigner {
|
||||
* @param charset 编码
|
||||
* @return 编码
|
||||
*/
|
||||
public HMacJWTSigner setCharset(Charset charset) {
|
||||
public HMacJWTSigner setCharset(final Charset charset) {
|
||||
this.charset = charset;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sign(String headerBase64, String payloadBase64) {
|
||||
public String sign(final String headerBase64, final String payloadBase64) {
|
||||
return hMac.digestBase64(StrUtil.format("{}.{}", headerBase64, payloadBase64), charset, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String headerBase64, String payloadBase64, String signBase64) {
|
||||
public boolean verify(final String headerBase64, final String payloadBase64, final String signBase64) {
|
||||
final String sign = sign(headerBase64, payloadBase64);
|
||||
return hMac.verify(
|
||||
StrUtil.bytes(sign, charset),
|
||||
|
@@ -32,7 +32,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner hs256(byte[] key) {
|
||||
public static JWTSigner hs256(final byte[] key) {
|
||||
return createSigner("HS256", key);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner hs384(byte[] key) {
|
||||
public static JWTSigner hs384(final byte[] key) {
|
||||
return createSigner("HS384", key);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner hs512(byte[] key) {
|
||||
public static JWTSigner hs512(final byte[] key) {
|
||||
return createSigner("HS512", key);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner rs256(Key key) {
|
||||
public static JWTSigner rs256(final Key key) {
|
||||
return createSigner("RS256", key);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner rs384(Key key) {
|
||||
public static JWTSigner rs384(final Key key) {
|
||||
return createSigner("RS384", key);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner rs512(Key key) {
|
||||
public static JWTSigner rs512(final Key key) {
|
||||
return createSigner("RS512", key);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner es256(Key key) {
|
||||
public static JWTSigner es256(final Key key) {
|
||||
return createSigner("ES256", key);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner es384(Key key) {
|
||||
public static JWTSigner es384(final Key key) {
|
||||
return createSigner("ES384", key);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner es512(Key key) {
|
||||
public static JWTSigner es512(final Key key) {
|
||||
return createSigner("ES512", key);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner createSigner(String algorithmId, byte[] key) {
|
||||
public static JWTSigner createSigner(final String algorithmId, final byte[] key) {
|
||||
Assert.notNull(key, "Signer key must be not null!");
|
||||
|
||||
if (null == algorithmId || NoneJWTSigner.ID_NONE.equals(algorithmId)) {
|
||||
@@ -143,7 +143,7 @@ public class JWTSignerUtil {
|
||||
* @param keyPair 密钥对
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner createSigner(String algorithmId, KeyPair keyPair) {
|
||||
public static JWTSigner createSigner(final String algorithmId, final KeyPair keyPair) {
|
||||
Assert.notNull(keyPair, "Signer key pair must be not null!");
|
||||
|
||||
if (null == algorithmId || NoneJWTSigner.ID_NONE.equals(algorithmId)) {
|
||||
@@ -159,7 +159,7 @@ public class JWTSignerUtil {
|
||||
* @param key 密钥
|
||||
* @return 签名器
|
||||
*/
|
||||
public static JWTSigner createSigner(String algorithmId, Key key) {
|
||||
public static JWTSigner createSigner(final String algorithmId, final Key key) {
|
||||
Assert.notNull(key, "Signer key must be not null!");
|
||||
|
||||
if (null == algorithmId || NoneJWTSigner.ID_NONE.equals(algorithmId)) {
|
||||
|
@@ -15,12 +15,12 @@ public class NoneJWTSigner implements JWTSigner {
|
||||
public static NoneJWTSigner NONE = new NoneJWTSigner();
|
||||
|
||||
@Override
|
||||
public String sign(String headerBase64, String payloadBase64) {
|
||||
public String sign(final String headerBase64, final String payloadBase64) {
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verify(String headerBase64, String payloadBase64, String signBase64) {
|
||||
public boolean verify(final String headerBase64, final String payloadBase64, final String signBase64) {
|
||||
return StrUtil.isEmpty(signBase64);
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,7 @@ public class GlobalSerializeMapping {
|
||||
* @param type 对象类型
|
||||
* @param serializer 序列化器实现
|
||||
*/
|
||||
public static void put(Type type, JSONArraySerializer<?> serializer) {
|
||||
public static void put(final Type type, final JSONArraySerializer<?> serializer) {
|
||||
putInternal(type, serializer);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class GlobalSerializeMapping {
|
||||
* @param type 对象类型
|
||||
* @param serializer 序列化器实现
|
||||
*/
|
||||
public static void put(Type type, JSONObjectSerializer<?> serializer) {
|
||||
public static void put(final Type type, final JSONObjectSerializer<?> serializer) {
|
||||
putInternal(type, serializer);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class GlobalSerializeMapping {
|
||||
* @param type 对象类型
|
||||
* @param serializer 序列化器实现
|
||||
*/
|
||||
synchronized private static void putInternal(Type type, JSONSerializer<? extends JSON, ?> serializer) {
|
||||
synchronized private static void putInternal(final Type type, final JSONSerializer<? extends JSON, ?> serializer) {
|
||||
if(null == serializerMap) {
|
||||
serializerMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class GlobalSerializeMapping {
|
||||
* @param type 对象类型
|
||||
* @param deserializer 反序列化器实现
|
||||
*/
|
||||
synchronized public static void put(Type type, JSONDeserializer<?> deserializer) {
|
||||
synchronized public static void put(final Type type, final JSONDeserializer<?> deserializer) {
|
||||
if(null == deserializerMap) {
|
||||
deserializerMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public class GlobalSerializeMapping {
|
||||
* @param type 类型
|
||||
* @return 自定义的序列化器或者{@code null}
|
||||
*/
|
||||
public static JSONSerializer<? extends JSON, ?> getSerializer(Type type){
|
||||
public static JSONSerializer<? extends JSON, ?> getSerializer(final Type type){
|
||||
if(null == serializerMap) {
|
||||
return null;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class GlobalSerializeMapping {
|
||||
* @param type 类型
|
||||
* @return 自定义的反序列化器或者{@code null}
|
||||
*/
|
||||
public static JSONDeserializer<?> getDeserializer(Type type){
|
||||
public static JSONDeserializer<?> getDeserializer(final Type type){
|
||||
if(null == deserializerMap) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ public class JSONWriter extends Writer {
|
||||
* @param config JSON选项
|
||||
* @return JSONWriter
|
||||
*/
|
||||
public static JSONWriter of(Writer writer, int indentFactor, int indent, JSONConfig config) {
|
||||
public static JSONWriter of(final Writer writer, final int indentFactor, final int indent, final JSONConfig config) {
|
||||
return new JSONWriter(writer, indentFactor, indent, config);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class JSONWriter extends Writer {
|
||||
* @param indent 本级别缩进量
|
||||
* @param config JSON选项
|
||||
*/
|
||||
public JSONWriter(Writer writer, int indentFactor, int indent, JSONConfig config) {
|
||||
public JSONWriter(final Writer writer, final int indentFactor, final int indent, final JSONConfig config) {
|
||||
this.writer = writer;
|
||||
this.indentFactor = indentFactor;
|
||||
this.indent = indent;
|
||||
@@ -132,7 +132,7 @@ public class JSONWriter extends Writer {
|
||||
* @param key 键名
|
||||
* @return this
|
||||
*/
|
||||
public JSONWriter writeKey(String key) {
|
||||
public JSONWriter writeKey(final String key) {
|
||||
if (needSeparator) {
|
||||
writeRaw(CharUtil.COMMA);
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class JSONWriter extends Writer {
|
||||
* @param value 值
|
||||
* @return this
|
||||
*/
|
||||
public JSONWriter writeValue(Object value) {
|
||||
public JSONWriter writeValue(final Object value) {
|
||||
if(JSONUtil.isNull(value) && config.isIgnoreNullValue()){
|
||||
return this;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class JSONWriter extends Writer {
|
||||
* @return this
|
||||
* @since 5.7.6
|
||||
*/
|
||||
public JSONWriter writeField(String key, Object value){
|
||||
public JSONWriter writeField(final String key, final Object value){
|
||||
if(JSONUtil.isNull(value) && config.isIgnoreNullValue()){
|
||||
return this;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public class JSONWriter extends Writer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(char[] cbuf, int off, int len) throws IOException {
|
||||
public void write(final char[] cbuf, final int off, final int len) throws IOException {
|
||||
this.writer.write(cbuf, off, len);
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class JSONWriter extends Writer {
|
||||
public void flush() {
|
||||
try {
|
||||
this.writer.flush();
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class JSONWriter extends Writer {
|
||||
* @param value 值
|
||||
* @return this
|
||||
*/
|
||||
private JSONWriter writeValueDirect(Object value) {
|
||||
private JSONWriter writeValueDirect(final Object value) {
|
||||
if (arrayMode) {
|
||||
if (needSeparator) {
|
||||
writeRaw(CharUtil.COMMA);
|
||||
@@ -217,7 +217,7 @@ public class JSONWriter extends Writer {
|
||||
* @param value 值
|
||||
* @return this
|
||||
*/
|
||||
private JSONWriter writeObjValue(Object value) {
|
||||
private JSONWriter writeObjValue(final Object value) {
|
||||
final int indent = indentFactor + this.indent;
|
||||
if (value == null || value instanceof JSONNull) {
|
||||
writeRaw(JSONNull.NULL.toString());
|
||||
@@ -250,7 +250,7 @@ public class JSONWriter extends Writer {
|
||||
*
|
||||
* @param number 数字
|
||||
*/
|
||||
private void writeNumberValue(Number number) {
|
||||
private void writeNumberValue(final Number number) {
|
||||
// since 5.6.2可配置是否去除末尾多余0,例如如果为true,5.0返回5
|
||||
final boolean isStripTrailingZeros = null == config || config.isStripTrailingZeros();
|
||||
writeRaw(NumberUtil.toStr(number, isStripTrailingZeros));
|
||||
@@ -261,7 +261,7 @@ public class JSONWriter extends Writer {
|
||||
*
|
||||
* @param value Boolean值
|
||||
*/
|
||||
private void writeBooleanValue(Boolean value) {
|
||||
private void writeBooleanValue(final Boolean value) {
|
||||
writeRaw(value.toString());
|
||||
}
|
||||
|
||||
@@ -272,11 +272,11 @@ public class JSONWriter extends Writer {
|
||||
*
|
||||
* @param jsonString {@link JSONString}
|
||||
*/
|
||||
private void writeJSONStringValue(JSONString jsonString) {
|
||||
String valueStr;
|
||||
private void writeJSONStringValue(final JSONString jsonString) {
|
||||
final String valueStr;
|
||||
try {
|
||||
valueStr = jsonString.toJSONString();
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
if (null != valueStr) {
|
||||
@@ -294,10 +294,10 @@ public class JSONWriter extends Writer {
|
||||
*
|
||||
* @param csq 字符串
|
||||
*/
|
||||
private void writeStrValue(String csq) {
|
||||
private void writeStrValue(final String csq) {
|
||||
try {
|
||||
JSONUtil.quote(csq, writer);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -307,7 +307,7 @@ public class JSONWriter extends Writer {
|
||||
*
|
||||
* @param count 空格数
|
||||
*/
|
||||
private void writeSpace(int count) {
|
||||
private void writeSpace(final int count) {
|
||||
if (indentFactor > 0) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
writeRaw(CharUtil.SPACE);
|
||||
@@ -333,10 +333,10 @@ public class JSONWriter extends Writer {
|
||||
* @param csq 字符串
|
||||
* @return this
|
||||
*/
|
||||
private JSONWriter writeRaw(String csq) {
|
||||
private JSONWriter writeRaw(final String csq) {
|
||||
try {
|
||||
writer.append(csq);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
@@ -348,10 +348,10 @@ public class JSONWriter extends Writer {
|
||||
* @param c 字符串
|
||||
* @return this
|
||||
*/
|
||||
private JSONWriter writeRaw(char c) {
|
||||
private JSONWriter writeRaw(final char c) {
|
||||
try {
|
||||
writer.write(c);
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
return this;
|
||||
@@ -364,7 +364,7 @@ public class JSONWriter extends Writer {
|
||||
* @param format 格式
|
||||
* @return 日期字符串
|
||||
*/
|
||||
private static String formatDate(Object dateObj, String format) {
|
||||
private static String formatDate(final Object dateObj, final String format) {
|
||||
if (StrUtil.isNotBlank(format)) {
|
||||
final String dateStr;
|
||||
if (dateObj instanceof TemporalAccessor) {
|
||||
@@ -383,7 +383,7 @@ public class JSONWriter extends Writer {
|
||||
}
|
||||
|
||||
//默认使用时间戳
|
||||
long timeMillis;
|
||||
final long timeMillis;
|
||||
if (dateObj instanceof TemporalAccessor) {
|
||||
timeMillis = TemporalAccessorUtil.toEpochMilli((TemporalAccessor) dateObj);
|
||||
} else if (dateObj instanceof Date) {
|
||||
|
@@ -27,12 +27,12 @@ public class TemporalAccessorSerializer implements JSONObjectSerializer<Temporal
|
||||
|
||||
private final Class<? extends TemporalAccessor> temporalAccessorClass;
|
||||
|
||||
public TemporalAccessorSerializer(Class<? extends TemporalAccessor> temporalAccessorClass) {
|
||||
public TemporalAccessorSerializer(final Class<? extends TemporalAccessor> temporalAccessorClass) {
|
||||
this.temporalAccessorClass = temporalAccessorClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JSONObject json, TemporalAccessor bean) {
|
||||
public void serialize(final JSONObject json, final TemporalAccessor bean) {
|
||||
if (bean instanceof LocalDate) {
|
||||
final LocalDate localDate = (LocalDate) bean;
|
||||
json.set(YEAR_KEY, localDate.getYear());
|
||||
@@ -59,7 +59,7 @@ public class TemporalAccessorSerializer implements JSONObjectSerializer<Temporal
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemporalAccessor deserialize(JSON json) {
|
||||
public TemporalAccessor deserialize(final JSON json) {
|
||||
final JSONObject jsonObject = (JSONObject) json;
|
||||
if (LocalDate.class.equals(this.temporalAccessorClass)) {
|
||||
return LocalDate.of(jsonObject.getInt(YEAR_KEY), jsonObject.getInt(MONTH_KEY), jsonObject.getInt(DAY_KEY));
|
||||
|
@@ -23,8 +23,8 @@ public class JSONXMLParser {
|
||||
* @param keepStrings 如果为{@code true},则值保持String类型,不转换为数字或boolean
|
||||
* @throws JSONException 解析异常
|
||||
*/
|
||||
public static void parseJSONObject(JSONObject jo, String xmlStr, boolean keepStrings) throws JSONException {
|
||||
XMLTokener x = new XMLTokener(xmlStr, jo.getConfig());
|
||||
public static void parseJSONObject(final JSONObject jo, final String xmlStr, final boolean keepStrings) throws JSONException {
|
||||
final XMLTokener x = new XMLTokener(xmlStr, jo.getConfig());
|
||||
while (x.more() && x.skipPast("<")) {
|
||||
parse(x, jo, null, keepStrings);
|
||||
}
|
||||
@@ -39,12 +39,12 @@ public class JSONXMLParser {
|
||||
* @return true if the close tag is processed.
|
||||
* @throws JSONException JSON异常
|
||||
*/
|
||||
private static boolean parse(XMLTokener x, JSONObject context, String name, boolean keepStrings) throws JSONException {
|
||||
char c;
|
||||
private static boolean parse(final XMLTokener x, final JSONObject context, final String name, final boolean keepStrings) throws JSONException {
|
||||
final char c;
|
||||
int i;
|
||||
JSONObject jsonobject;
|
||||
final JSONObject jsonobject;
|
||||
String string;
|
||||
String tagName;
|
||||
final String tagName;
|
||||
Object token;
|
||||
|
||||
token = x.nextToken();
|
||||
|
@@ -23,7 +23,7 @@ public class JSONXMLSerializer {
|
||||
* @return A string.
|
||||
* @throws JSONException Thrown if there is an error parsing the string
|
||||
*/
|
||||
public static String toXml(Object object) throws JSONException {
|
||||
public static String toXml(final Object object) throws JSONException {
|
||||
return toXml(object, null);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class JSONXMLSerializer {
|
||||
* @return A string.
|
||||
* @throws JSONException JSON解析异常
|
||||
*/
|
||||
public static String toXml(Object object, String tagName) throws JSONException {
|
||||
public static String toXml(final Object object, final String tagName) throws JSONException {
|
||||
return toXml(object, tagName, "content");
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JSONXMLSerializer {
|
||||
* @return A string.
|
||||
* @throws JSONException JSON解析异常
|
||||
*/
|
||||
public static String toXml(Object object, String tagName, String... contentKeys) throws JSONException {
|
||||
public static String toXml(Object object, final String tagName, final String... contentKeys) throws JSONException {
|
||||
if (null == object) {
|
||||
return null;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class JSONXMLSerializer {
|
||||
if (ArrayUtil.contains(contentKeys, key)) {
|
||||
if (value instanceof JSONArray) {
|
||||
int i = 0;
|
||||
for (Object val : (JSONArray) value) {
|
||||
for (final Object val : (JSONArray) value) {
|
||||
if (i > 0) {
|
||||
sb.append(CharUtil.LF);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class JSONXMLSerializer {
|
||||
} else if (StrUtil.isEmptyIfStr(value)) {
|
||||
sb.append(wrapWithTag(null, key));
|
||||
} else if (value instanceof JSONArray) {
|
||||
for (Object val : (JSONArray) value) {
|
||||
for (final Object val : (JSONArray) value) {
|
||||
if (val instanceof JSONArray) {
|
||||
sb.append(wrapWithTag(toXml(val), key));
|
||||
} else {
|
||||
@@ -107,7 +107,7 @@ public class JSONXMLSerializer {
|
||||
}
|
||||
|
||||
if (object instanceof JSONArray) {
|
||||
for (Object val : (JSONArray) object) {
|
||||
for (final Object val : (JSONArray) object) {
|
||||
// XML does not have good support for arrays. If an array
|
||||
// appears in a place where XML is lacking, synthesize an
|
||||
// <array> element.
|
||||
@@ -127,7 +127,7 @@ public class JSONXMLSerializer {
|
||||
* @param isEndTag 是否结束标签
|
||||
* @since 5.7.11
|
||||
*/
|
||||
private static void appendTag(StringBuilder sb, String tagName, boolean isEndTag) {
|
||||
private static void appendTag(final StringBuilder sb, final String tagName, final boolean isEndTag) {
|
||||
if (StrUtil.isNotBlank(tagName)) {
|
||||
sb.append('<');
|
||||
if (isEndTag) {
|
||||
@@ -145,7 +145,7 @@ public class JSONXMLSerializer {
|
||||
* @return 包装后的XML
|
||||
* @since 5.7.11
|
||||
*/
|
||||
private static String wrapWithTag(String content, String tagName) {
|
||||
private static String wrapWithTag(final String content, final String tagName) {
|
||||
if (StrUtil.isBlank(tagName)) {
|
||||
return StrUtil.wrap(content, "\"");
|
||||
}
|
||||
|
Reference in New Issue
Block a user