1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Replaced tab chars, updated versions

This commit is contained in:
stleary 2015-05-05 20:11:28 -05:00
parent b56fe9fea9
commit a851bf0951
2 changed files with 24 additions and 12 deletions

View file

@ -91,7 +91,7 @@ import java.util.Set;
* </ul> * </ul>
* *
* @author JSON.org * @author JSON.org
* @version 2014-05-03 * @version 2015-05-05
*/ */
public class JSONObject { public class JSONObject {
/** /**
@ -298,7 +298,7 @@ public class JSONObject {
*/ */
public JSONObject(Object object, String names[]) { public JSONObject(Object object, String names[]) {
this(); this();
Class c = object.getClass(); Class<?> c = object.getClass();
for (int i = 0; i < names.length; i += 1) { for (int i = 0; i < names.length; i += 1) {
String name = names[i]; String name = names[i];
try { try {
@ -631,7 +631,7 @@ public class JSONObject {
if (object == null) { if (object == null) {
return null; return null;
} }
Class klass = object.getClass(); Class<?> klass = object.getClass();
Field[] fields = klass.getFields(); Field[] fields = klass.getFields();
int length = fields.length; int length = fields.length;
if (length == 0) { if (length == 0) {
@ -981,7 +981,7 @@ public class JSONObject {
} }
private void populateMap(Object bean) { private void populateMap(Object bean) {
Class klass = bean.getClass(); Class<?> klass = bean.getClass();
// If klass is a System class then set includeSuperClass to false. // If klass is a System class then set includeSuperClass to false.
@ -1512,10 +1512,14 @@ public class JSONObject {
return value.toString(); return value.toString();
} }
if (value instanceof Map) { if (value instanceof Map) {
return new JSONObject((Map<String, Object>)value).toString(); @SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) value;
return new JSONObject(map).toString();
} }
if (value instanceof Collection) { if (value instanceof Collection) {
return new JSONArray((Collection<Object>) value).toString(); @SuppressWarnings("unchecked")
Collection<Object> coll = (Collection<Object>) value;
return new JSONArray(coll).toString();
} }
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
return new JSONArray(value).toString(); return new JSONArray(value).toString();
@ -1551,13 +1555,17 @@ public class JSONObject {
} }
if (object instanceof Collection) { if (object instanceof Collection) {
return new JSONArray((Collection<Object>) object); @SuppressWarnings("unchecked")
Collection<Object> coll = (Collection<Object>) object;
return new JSONArray(coll);
} }
if (object.getClass().isArray()) { if (object.getClass().isArray()) {
return new JSONArray(object); return new JSONArray(object);
} }
if (object instanceof Map) { if (object instanceof Map) {
return new JSONObject((Map<String, Object>) object); @SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) object;
return new JSONObject(map);
} }
Package objectPackage = object.getClass().getPackage(); Package objectPackage = object.getClass().getPackage();
String objectPackageName = objectPackage != null ? objectPackage String objectPackageName = objectPackage != null ? objectPackage
@ -1595,9 +1603,13 @@ public class JSONObject {
} else if (value instanceof JSONArray) { } else if (value instanceof JSONArray) {
((JSONArray) value).write(writer, indentFactor, indent); ((JSONArray) value).write(writer, indentFactor, indent);
} else if (value instanceof Map) { } else if (value instanceof Map) {
new JSONObject((Map<String, Object>) value).write(writer, indentFactor, indent); @SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) value;
new JSONObject(map).write(writer, indentFactor, indent);
} else if (value instanceof Collection) { } else if (value instanceof Collection) {
new JSONArray((Collection<Object>) value).write(writer, indentFactor, @SuppressWarnings("unchecked")
Collection<Object> coll = (Collection<Object>) value;
new JSONArray(coll).write(writer, indentFactor,
indent); indent);
} else if (value.getClass().isArray()) { } else if (value.getClass().isArray()) {
new JSONArray(value).write(writer, indentFactor, indent); new JSONArray(value).write(writer, indentFactor, indent);

View file

@ -31,7 +31,7 @@ import java.util.Properties;
/** /**
* Converts a Property file data into JSONObject and back. * Converts a Property file data into JSONObject and back.
* @author JSON.org * @author JSON.org
* @version 2014-05-03 * @version 2015-05-05
*/ */
public class Property { public class Property {
/** /**
@ -43,7 +43,7 @@ public class Property {
public static JSONObject toJSONObject(java.util.Properties properties) throws JSONException { public static JSONObject toJSONObject(java.util.Properties properties) throws JSONException {
JSONObject jo = new JSONObject(); JSONObject jo = new JSONObject();
if (properties != null && !properties.isEmpty()) { if (properties != null && !properties.isEmpty()) {
Enumeration enumProperties = properties.propertyNames(); Enumeration<?> enumProperties = properties.propertyNames();
while(enumProperties.hasMoreElements()) { while(enumProperties.hasMoreElements()) {
String name = (String)enumProperties.nextElement(); String name = (String)enumProperties.nextElement();
jo.put(name, properties.getProperty(name)); jo.put(name, properties.getProperty(name));