mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
Merge pull request #769 from jscrdev/fixed-warnings
Addressed Java 17 compile warnings
This commit is contained in:
commit
01727fd0ed
@ -368,16 +368,16 @@ public class JSONArrayTest {
|
|||||||
"hello".equals(jsonArray.getString(4)));
|
"hello".equals(jsonArray.getString(4)));
|
||||||
// doubles
|
// doubles
|
||||||
assertTrue("Array double",
|
assertTrue("Array double",
|
||||||
new Double(23.45e-4).equals(jsonArray.getDouble(5)));
|
Double.valueOf(23.45e-4).equals(jsonArray.getDouble(5)));
|
||||||
assertTrue("Array string double",
|
assertTrue("Array string double",
|
||||||
new Double(23.45).equals(jsonArray.getDouble(6)));
|
Double.valueOf(23.45).equals(jsonArray.getDouble(6)));
|
||||||
assertTrue("Array double can be float",
|
assertTrue("Array double can be float",
|
||||||
new Float(23.45e-4f).equals(jsonArray.getFloat(5)));
|
Float.valueOf(23.45e-4f).equals(jsonArray.getFloat(5)));
|
||||||
// ints
|
// ints
|
||||||
assertTrue("Array value int",
|
assertTrue("Array value int",
|
||||||
new Integer(42).equals(jsonArray.getInt(7)));
|
Integer.valueOf(42).equals(jsonArray.getInt(7)));
|
||||||
assertTrue("Array value string int",
|
assertTrue("Array value string int",
|
||||||
new Integer(43).equals(jsonArray.getInt(8)));
|
Integer.valueOf(43).equals(jsonArray.getInt(8)));
|
||||||
// nested objects
|
// nested objects
|
||||||
JSONArray nestedJsonArray = jsonArray.getJSONArray(9);
|
JSONArray nestedJsonArray = jsonArray.getJSONArray(9);
|
||||||
assertTrue("Array value JSONArray", nestedJsonArray != null);
|
assertTrue("Array value JSONArray", nestedJsonArray != null);
|
||||||
@ -385,9 +385,9 @@ public class JSONArrayTest {
|
|||||||
assertTrue("Array value JSONObject", nestedJsonObject != null);
|
assertTrue("Array value JSONObject", nestedJsonObject != null);
|
||||||
// longs
|
// longs
|
||||||
assertTrue("Array value long",
|
assertTrue("Array value long",
|
||||||
new Long(0).equals(jsonArray.getLong(11)));
|
Long.valueOf(0).equals(jsonArray.getLong(11)));
|
||||||
assertTrue("Array value string long",
|
assertTrue("Array value string long",
|
||||||
new Long(-1).equals(jsonArray.getLong(12)));
|
Long.valueOf(-1).equals(jsonArray.getLong(12)));
|
||||||
|
|
||||||
assertTrue("Array value null", jsonArray.isNull(-1));
|
assertTrue("Array value null", jsonArray.isNull(-1));
|
||||||
Util.checkJSONArrayMaps(jsonArray);
|
Util.checkJSONArrayMaps(jsonArray);
|
||||||
@ -545,11 +545,11 @@ public class JSONArrayTest {
|
|||||||
Boolean.FALSE.equals(jsonArray.optBooleanObject(-1)));
|
Boolean.FALSE.equals(jsonArray.optBooleanObject(-1)));
|
||||||
|
|
||||||
assertTrue("Array opt double",
|
assertTrue("Array opt double",
|
||||||
new Double(23.45e-4).equals(jsonArray.optDouble(5)));
|
Double.valueOf(23.45e-4).equals(jsonArray.optDouble(5)));
|
||||||
assertTrue("Array opt double default",
|
assertTrue("Array opt double default",
|
||||||
new Double(1).equals(jsonArray.optDouble(0, 1)));
|
Double.valueOf(1).equals(jsonArray.optDouble(0, 1)));
|
||||||
assertTrue("Array opt double default implicit",
|
assertTrue("Array opt double default implicit",
|
||||||
new Double(jsonArray.optDouble(99)).isNaN());
|
Double.valueOf(jsonArray.optDouble(99)).isNaN());
|
||||||
|
|
||||||
assertTrue("Array opt double object",
|
assertTrue("Array opt double object",
|
||||||
Double.valueOf(23.45e-4).equals(jsonArray.optDoubleObject(5)));
|
Double.valueOf(23.45e-4).equals(jsonArray.optDoubleObject(5)));
|
||||||
@ -559,11 +559,11 @@ public class JSONArrayTest {
|
|||||||
jsonArray.optDoubleObject(99).isNaN());
|
jsonArray.optDoubleObject(99).isNaN());
|
||||||
|
|
||||||
assertTrue("Array opt float",
|
assertTrue("Array opt float",
|
||||||
new Float(23.45e-4).equals(jsonArray.optFloat(5)));
|
Float.valueOf(Double.valueOf(23.45e-4).floatValue()).equals(jsonArray.optFloat(5)));
|
||||||
assertTrue("Array opt float default",
|
assertTrue("Array opt float default",
|
||||||
new Float(1).equals(jsonArray.optFloat(0, 1)));
|
Float.valueOf(1).equals(jsonArray.optFloat(0, 1)));
|
||||||
assertTrue("Array opt float default implicit",
|
assertTrue("Array opt float default implicit",
|
||||||
new Float(jsonArray.optFloat(99)).isNaN());
|
Float.valueOf(jsonArray.optFloat(99)).isNaN());
|
||||||
|
|
||||||
assertTrue("Array opt float object",
|
assertTrue("Array opt float object",
|
||||||
Float.valueOf(23.45e-4F).equals(jsonArray.optFloatObject(5)));
|
Float.valueOf(23.45e-4F).equals(jsonArray.optFloatObject(5)));
|
||||||
@ -575,14 +575,14 @@ public class JSONArrayTest {
|
|||||||
assertTrue("Array opt Number",
|
assertTrue("Array opt Number",
|
||||||
BigDecimal.valueOf(23.45e-4).equals(jsonArray.optNumber(5)));
|
BigDecimal.valueOf(23.45e-4).equals(jsonArray.optNumber(5)));
|
||||||
assertTrue("Array opt Number default",
|
assertTrue("Array opt Number default",
|
||||||
new Double(1).equals(jsonArray.optNumber(0, 1d)));
|
Double.valueOf(1).equals(jsonArray.optNumber(0, 1d)));
|
||||||
assertTrue("Array opt Number default implicit",
|
assertTrue("Array opt Number default implicit",
|
||||||
new Double(jsonArray.optNumber(99,Double.NaN).doubleValue()).isNaN());
|
Double.valueOf(jsonArray.optNumber(99,Double.NaN).doubleValue()).isNaN());
|
||||||
|
|
||||||
assertTrue("Array opt int",
|
assertTrue("Array opt int",
|
||||||
new Integer(42).equals(jsonArray.optInt(7)));
|
Integer.valueOf(42).equals(jsonArray.optInt(7)));
|
||||||
assertTrue("Array opt int default",
|
assertTrue("Array opt int default",
|
||||||
new Integer(-1).equals(jsonArray.optInt(0, -1)));
|
Integer.valueOf(-1).equals(jsonArray.optInt(0, -1)));
|
||||||
assertTrue("Array opt int default implicit",
|
assertTrue("Array opt int default implicit",
|
||||||
0 == jsonArray.optInt(0));
|
0 == jsonArray.optInt(0));
|
||||||
|
|
||||||
@ -1011,12 +1011,12 @@ public class JSONArrayTest {
|
|||||||
assertTrue("Array double [23.45e-4]",
|
assertTrue("Array double [23.45e-4]",
|
||||||
new BigDecimal("0.002345").equals(it.next()));
|
new BigDecimal("0.002345").equals(it.next()));
|
||||||
assertTrue("Array string double",
|
assertTrue("Array string double",
|
||||||
new Double(23.45).equals(Double.parseDouble((String)it.next())));
|
Double.valueOf(23.45).equals(Double.parseDouble((String)it.next())));
|
||||||
|
|
||||||
assertTrue("Array value int",
|
assertTrue("Array value int",
|
||||||
new Integer(42).equals(it.next()));
|
Integer.valueOf(42).equals(it.next()));
|
||||||
assertTrue("Array value string int",
|
assertTrue("Array value string int",
|
||||||
new Integer(43).equals(Integer.parseInt((String)it.next())));
|
Integer.valueOf(43).equals(Integer.parseInt((String)it.next())));
|
||||||
|
|
||||||
JSONArray nestedJsonArray = (JSONArray)it.next();
|
JSONArray nestedJsonArray = (JSONArray)it.next();
|
||||||
assertTrue("Array value JSONArray", nestedJsonArray != null);
|
assertTrue("Array value JSONArray", nestedJsonArray != null);
|
||||||
@ -1025,9 +1025,9 @@ public class JSONArrayTest {
|
|||||||
assertTrue("Array value JSONObject", nestedJsonObject != null);
|
assertTrue("Array value JSONObject", nestedJsonObject != null);
|
||||||
|
|
||||||
assertTrue("Array value long",
|
assertTrue("Array value long",
|
||||||
new Long(0).equals(((Number) it.next()).longValue()));
|
Long.valueOf(0).equals(((Number) it.next()).longValue()));
|
||||||
assertTrue("Array value string long",
|
assertTrue("Array value string long",
|
||||||
new Long(-1).equals(Long.parseLong((String) it.next())));
|
Long.valueOf(-1).equals(Long.parseLong((String) it.next())));
|
||||||
assertTrue("should be at end of array", !it.hasNext());
|
assertTrue("should be at end of array", !it.hasNext());
|
||||||
Util.checkJSONArraysMaps(new ArrayList<JSONArray>(Arrays.asList(
|
Util.checkJSONArraysMaps(new ArrayList<JSONArray>(Arrays.asList(
|
||||||
jsonArray, nestedJsonArray
|
jsonArray, nestedJsonArray
|
||||||
|
@ -54,7 +54,6 @@ import org.json.junit.data.Singleton;
|
|||||||
import org.json.junit.data.SingletonEnum;
|
import org.json.junit.data.SingletonEnum;
|
||||||
import org.json.junit.data.WeirdList;
|
import org.json.junit.data.WeirdList;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.json.junit.Util;
|
|
||||||
|
|
||||||
import com.jayway.jsonpath.Configuration;
|
import com.jayway.jsonpath.Configuration;
|
||||||
import com.jayway.jsonpath.JsonPath;
|
import com.jayway.jsonpath.JsonPath;
|
||||||
@ -304,12 +303,12 @@ public class JSONObjectTest {
|
|||||||
@Test
|
@Test
|
||||||
public void jsonObjectByMap() {
|
public void jsonObjectByMap() {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("trueKey", new Boolean(true));
|
map.put("trueKey", Boolean.valueOf(true));
|
||||||
map.put("falseKey", new Boolean(false));
|
map.put("falseKey", Boolean.valueOf(false));
|
||||||
map.put("stringKey", "hello world!");
|
map.put("stringKey", "hello world!");
|
||||||
map.put("escapeStringKey", "h\be\tllo w\u1234orld!");
|
map.put("escapeStringKey", "h\be\tllo w\u1234orld!");
|
||||||
map.put("intKey", new Long(42));
|
map.put("intKey", Long.valueOf(42));
|
||||||
map.put("doubleKey", new Double(-23.45e67));
|
map.put("doubleKey", Double.valueOf(-23.45e67));
|
||||||
JSONObject jsonObject = new JSONObject(map);
|
JSONObject jsonObject = new JSONObject(map);
|
||||||
|
|
||||||
// validate JSON
|
// validate JSON
|
||||||
@ -570,13 +569,13 @@ public class JSONObjectTest {
|
|||||||
@Test
|
@Test
|
||||||
public void jsonObjectByMapWithNullValue() {
|
public void jsonObjectByMapWithNullValue() {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("trueKey", new Boolean(true));
|
map.put("trueKey", Boolean.valueOf(true));
|
||||||
map.put("falseKey", new Boolean(false));
|
map.put("falseKey", Boolean.valueOf(false));
|
||||||
map.put("stringKey", "hello world!");
|
map.put("stringKey", "hello world!");
|
||||||
map.put("nullKey", null);
|
map.put("nullKey", null);
|
||||||
map.put("escapeStringKey", "h\be\tllo w\u1234orld!");
|
map.put("escapeStringKey", "h\be\tllo w\u1234orld!");
|
||||||
map.put("intKey", new Long(42));
|
map.put("intKey", Long.valueOf(42));
|
||||||
map.put("doubleKey", new Double(-23.45e67));
|
map.put("doubleKey", Double.valueOf(-23.45e67));
|
||||||
JSONObject jsonObject = new JSONObject(map);
|
JSONObject jsonObject = new JSONObject(map);
|
||||||
|
|
||||||
// validate JSON
|
// validate JSON
|
||||||
@ -996,7 +995,7 @@ public class JSONObjectTest {
|
|||||||
assertTrue( "0.2 should be a BigDecimal!",
|
assertTrue( "0.2 should be a BigDecimal!",
|
||||||
JSONObject.stringToValue( "0.2" ) instanceof BigDecimal );
|
JSONObject.stringToValue( "0.2" ) instanceof BigDecimal );
|
||||||
assertTrue( "Doubles should be BigDecimal, even when incorrectly converting floats!",
|
assertTrue( "Doubles should be BigDecimal, even when incorrectly converting floats!",
|
||||||
JSONObject.stringToValue( new Double( "0.2f" ).toString() ) instanceof BigDecimal );
|
JSONObject.stringToValue( Double.valueOf( "0.2f" ).toString() ) instanceof BigDecimal );
|
||||||
/**
|
/**
|
||||||
* This test documents a need for BigDecimal conversion.
|
* This test documents a need for BigDecimal conversion.
|
||||||
*/
|
*/
|
||||||
@ -1006,13 +1005,13 @@ public class JSONObjectTest {
|
|||||||
assertTrue( "1 should be an Integer!",
|
assertTrue( "1 should be an Integer!",
|
||||||
JSONObject.stringToValue( "1" ) instanceof Integer );
|
JSONObject.stringToValue( "1" ) instanceof Integer );
|
||||||
assertTrue( "Integer.MAX_VALUE should still be an Integer!",
|
assertTrue( "Integer.MAX_VALUE should still be an Integer!",
|
||||||
JSONObject.stringToValue( new Integer( Integer.MAX_VALUE ).toString() ) instanceof Integer );
|
JSONObject.stringToValue( Integer.valueOf( Integer.MAX_VALUE ).toString() ) instanceof Integer );
|
||||||
assertTrue( "Large integers should be a Long!",
|
assertTrue( "Large integers should be a Long!",
|
||||||
JSONObject.stringToValue( Long.valueOf(((long)Integer.MAX_VALUE) + 1 ) .toString() ) instanceof Long );
|
JSONObject.stringToValue( Long.valueOf(((long)Integer.MAX_VALUE) + 1 ) .toString() ) instanceof Long );
|
||||||
assertTrue( "Long.MAX_VALUE should still be an Integer!",
|
assertTrue( "Long.MAX_VALUE should still be an Integer!",
|
||||||
JSONObject.stringToValue( new Long( Long.MAX_VALUE ).toString() ) instanceof Long );
|
JSONObject.stringToValue( Long.valueOf( Long.MAX_VALUE ).toString() ) instanceof Long );
|
||||||
|
|
||||||
String str = new BigInteger( new Long( Long.MAX_VALUE ).toString() ).add( BigInteger.ONE ).toString();
|
String str = new BigInteger( Long.valueOf( Long.MAX_VALUE ).toString() ).add( BigInteger.ONE ).toString();
|
||||||
assertTrue( "Really large integers currently evaluate to BigInteger",
|
assertTrue( "Really large integers currently evaluate to BigInteger",
|
||||||
JSONObject.stringToValue(str).equals(new BigInteger("9223372036854775808")));
|
JSONObject.stringToValue(str).equals(new BigInteger("9223372036854775808")));
|
||||||
}
|
}
|
||||||
@ -1259,8 +1258,8 @@ public class JSONObjectTest {
|
|||||||
String key30 = "key30";
|
String key30 = "key30";
|
||||||
String key31 = "key31";
|
String key31 = "key31";
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put(key30, new Double(3.0));
|
jsonObject.put(key30, Double.valueOf(3.0));
|
||||||
jsonObject.put(key31, new Double(3.1));
|
jsonObject.put(key31, Double.valueOf(3.1));
|
||||||
|
|
||||||
assertTrue("3.0 should remain a double",
|
assertTrue("3.0 should remain a double",
|
||||||
jsonObject.getDouble(key30) == 3);
|
jsonObject.getDouble(key30) == 3);
|
||||||
@ -1713,19 +1712,19 @@ public class JSONObjectTest {
|
|||||||
*/
|
*/
|
||||||
assertFalse("Document unexpected behaviour with explicit type-casting float as double!", (double)0.2f == 0.2d );
|
assertFalse("Document unexpected behaviour with explicit type-casting float as double!", (double)0.2f == 0.2d );
|
||||||
assertFalse("Document unexpected behaviour with implicit type-cast!", 0.2f == 0.2d );
|
assertFalse("Document unexpected behaviour with implicit type-cast!", 0.2f == 0.2d );
|
||||||
Double d1 = new Double( 1.1f );
|
Double d1 = Double.valueOf( 1.1f );
|
||||||
Double d2 = new Double( "1.1f" );
|
Double d2 = Double.valueOf( "1.1f" );
|
||||||
assertFalse( "Document implicit type cast from float to double before calling Double(double d) constructor", d1.equals( d2 ) );
|
assertFalse( "Document implicit type cast from float to double before calling Double(double d) constructor", d1.equals( d2 ) );
|
||||||
|
|
||||||
assertTrue( "Correctly converting float to double via base10 (string) representation!", new Double( 3.1d ).equals( new Double( new Float( 3.1f ).toString() ) ) );
|
assertTrue( "Correctly converting float to double via base10 (string) representation!", Double.valueOf( 3.1d ).equals( Double.valueOf( Float.valueOf( 3.1f ).toString() ) ) );
|
||||||
|
|
||||||
// Pinpointing the not so obvious "buggy" conversion from float to double in JSONObject
|
// Pinpointing the not so obvious "buggy" conversion from float to double in JSONObject
|
||||||
JSONObject jo = new JSONObject();
|
JSONObject jo = new JSONObject();
|
||||||
jo.put( "bug", 3.1f ); // will call put( String key, double value ) with implicit and "buggy" type-cast from float to double
|
jo.put( "bug", 3.1f ); // will call put( String key, double value ) with implicit and "buggy" type-cast from float to double
|
||||||
assertFalse( "The java-compiler did add some zero bits for you to the mantissa (unexpected, but well documented)", jo.get( "bug" ).equals( new Double( 3.1d ) ) );
|
assertFalse( "The java-compiler did add some zero bits for you to the mantissa (unexpected, but well documented)", jo.get( "bug" ).equals( Double.valueOf( 3.1d ) ) );
|
||||||
|
|
||||||
JSONObject inc = new JSONObject();
|
JSONObject inc = new JSONObject();
|
||||||
inc.put( "bug", new Float( 3.1f ) ); // This will put in instance of Float into JSONObject, i.e. call put( String key, Object value )
|
inc.put( "bug", Float.valueOf( 3.1f ) ); // This will put in instance of Float into JSONObject, i.e. call put( String key, Object value )
|
||||||
assertTrue( "Everything is ok here!", inc.get( "bug" ) instanceof Float );
|
assertTrue( "Everything is ok here!", inc.get( "bug" ) instanceof Float );
|
||||||
inc.increment( "bug" ); // after adding 1, increment will call put( String key, double value ) with implicit and "buggy" type-cast from float to double!
|
inc.increment( "bug" ); // after adding 1, increment will call put( String key, double value ) with implicit and "buggy" type-cast from float to double!
|
||||||
// this.put(key, (Float) value + 1);
|
// this.put(key, (Float) value + 1);
|
||||||
@ -2040,14 +2039,14 @@ public class JSONObjectTest {
|
|||||||
assertTrue("map valueToString() incorrect",
|
assertTrue("map valueToString() incorrect",
|
||||||
jsonObject.toString().equals(JSONObject.valueToString(map)));
|
jsonObject.toString().equals(JSONObject.valueToString(map)));
|
||||||
Collection<Integer> collection = new ArrayList<Integer>();
|
Collection<Integer> collection = new ArrayList<Integer>();
|
||||||
collection.add(new Integer(1));
|
collection.add(Integer.valueOf(1));
|
||||||
collection.add(new Integer(2));
|
collection.add(Integer.valueOf(2));
|
||||||
collection.add(new Integer(3));
|
collection.add(Integer.valueOf(3));
|
||||||
assertTrue("collection valueToString() expected: "+
|
assertTrue("collection valueToString() expected: "+
|
||||||
jsonArray.toString()+ " actual: "+
|
jsonArray.toString()+ " actual: "+
|
||||||
JSONObject.valueToString(collection),
|
JSONObject.valueToString(collection),
|
||||||
jsonArray.toString().equals(JSONObject.valueToString(collection)));
|
jsonArray.toString().equals(JSONObject.valueToString(collection)));
|
||||||
Integer[] array = { new Integer(1), new Integer(2), new Integer(3) };
|
Integer[] array = { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3) };
|
||||||
assertTrue("array valueToString() incorrect",
|
assertTrue("array valueToString() incorrect",
|
||||||
jsonArray.toString().equals(JSONObject.valueToString(array)));
|
jsonArray.toString().equals(JSONObject.valueToString(array)));
|
||||||
Util.checkJSONObjectMaps(jsonObject);
|
Util.checkJSONObjectMaps(jsonObject);
|
||||||
@ -2085,7 +2084,7 @@ public class JSONObjectTest {
|
|||||||
JSONObject.NULL == JSONObject.wrap(null));
|
JSONObject.NULL == JSONObject.wrap(null));
|
||||||
|
|
||||||
// wrap(Integer) returns Integer
|
// wrap(Integer) returns Integer
|
||||||
Integer in = new Integer(1);
|
Integer in = Integer.valueOf(1);
|
||||||
assertTrue("Integer wrap() incorrect",
|
assertTrue("Integer wrap() incorrect",
|
||||||
in == JSONObject.wrap(in));
|
in == JSONObject.wrap(in));
|
||||||
|
|
||||||
@ -2112,9 +2111,9 @@ public class JSONObjectTest {
|
|||||||
|
|
||||||
// wrap collection returns JSONArray
|
// wrap collection returns JSONArray
|
||||||
Collection<Integer> collection = new ArrayList<Integer>();
|
Collection<Integer> collection = new ArrayList<Integer>();
|
||||||
collection.add(new Integer(1));
|
collection.add(Integer.valueOf(1));
|
||||||
collection.add(new Integer(2));
|
collection.add(Integer.valueOf(2));
|
||||||
collection.add(new Integer(3));
|
collection.add(Integer.valueOf(3));
|
||||||
JSONArray jsonArray = (JSONArray) (JSONObject.wrap(collection));
|
JSONArray jsonArray = (JSONArray) (JSONObject.wrap(collection));
|
||||||
|
|
||||||
// validate JSON
|
// validate JSON
|
||||||
@ -2125,7 +2124,7 @@ public class JSONObjectTest {
|
|||||||
assertTrue("expected 3", Integer.valueOf(3).equals(jsonArray.query("/2")));
|
assertTrue("expected 3", Integer.valueOf(3).equals(jsonArray.query("/2")));
|
||||||
|
|
||||||
// wrap Array returns JSONArray
|
// wrap Array returns JSONArray
|
||||||
Integer[] array = { new Integer(1), new Integer(2), new Integer(3) };
|
Integer[] array = { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3) };
|
||||||
JSONArray integerArrayJsonArray = (JSONArray)(JSONObject.wrap(array));
|
JSONArray integerArrayJsonArray = (JSONArray)(JSONObject.wrap(array));
|
||||||
|
|
||||||
// validate JSON
|
// validate JSON
|
||||||
|
Loading…
x
Reference in New Issue
Block a user