You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/01/06 16:21:55 UTC
svn commit: r1777637 - in /felix/trunk/configurator: ./
src/main/java/org/apache/felix/configurator/impl/json/
src/test/java/org/apache/felix/configurator/impl/
src/test/java/org/apache/felix/configurator/impl/json/
Author: cziegeler
Date: Fri Jan 6 16:21:55 2017
New Revision: 1777637
URL: http://svn.apache.org/viewvc?rev=1777637&view=rev
Log:
Use serializer service
Modified:
felix/trunk/configurator/pom.xml
felix/trunk/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java
felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java
Modified: felix/trunk/configurator/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/configurator/pom.xml?rev=1777637&r1=1777636&r2=1777637&view=diff
==============================================================================
--- felix/trunk/configurator/pom.xml (original)
+++ felix/trunk/configurator/pom.xml Fri Jan 6 16:21:55 2017
@@ -69,7 +69,7 @@
<Provide-Capability>
osgi.implementation;osgi.implementation="osgi.configurator";version:Version="1.0"
</Provide-Capability>
- <Embed-Dependency>geronimo-json_1.0_spec,johnzon-core</Embed-Dependency>
+ <Embed-Dependency>org.apache.felix.serializer,org.apache.felix.converter</Embed-Dependency>
</instructions>
</configuration>
</plugin>
@@ -106,6 +106,12 @@
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.serializer</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
<version>1.9.0-SNAPSHOT</version>
<scope>provided</scope>
@@ -122,17 +128,5 @@
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-json_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.johnzon</groupId>
- <artifactId>johnzon-core</artifactId>
- <version>0.9.5</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
</project>
Modified: felix/trunk/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java?rev=1777637&r1=1777636&r2=1777637&view=diff
==============================================================================
--- felix/trunk/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java (original)
+++ felix/trunk/configurator/src/main/java/org/apache/felix/configurator/impl/json/JSONUtil.java Fri Jan 6 16:21:55 2017
@@ -30,18 +30,9 @@ import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
import java.util.Set;
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonNumber;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.json.JsonString;
-import javax.json.JsonStructure;
-import javax.json.JsonValue;
-import javax.json.JsonValue.ValueType;
-
import org.apache.felix.configurator.impl.TypeConverter;
import org.apache.felix.configurator.impl.Util;
import org.apache.felix.configurator.impl.logger.SystemLogger;
@@ -49,7 +40,9 @@ import org.apache.felix.configurator.imp
import org.apache.felix.configurator.impl.model.Config;
import org.apache.felix.configurator.impl.model.ConfigPolicy;
import org.apache.felix.configurator.impl.model.ConfigurationFile;
+import org.apache.felix.serializer.impl.json.JsonSerializerImpl;
import org.osgi.framework.Bundle;
+import org.osgi.service.serializer.Serializer;
import org.osgi.util.converter.TypeReference;
public class JSONUtil {
@@ -138,16 +131,16 @@ public class JSONUtil {
final long bundleId,
final String contents) {
final String identifier = (url == null ? name : url.toString());
- final JsonObject json = parseJSON(name, contents);
+ final Map json = parseJSON(name, contents);
final List<?> configs = verifyJSON(name, json);
if ( configs != null ) {
final List<Config> configurations = new ArrayList<>();
for(final Object obj : configs) {
- if ( ! (obj instanceof JsonObject) ) {
+ if ( ! (obj instanceof Map) ) {
SystemLogger.error("Ignoring configuration in '" + identifier + "' (not a configuration) : " + obj);
} else {
- final JsonObject mainMap = (JsonObject)obj;
- final Object pid = getValue(mainMap, PROP_PID);
+ final Map mainMap = (Map)obj;
+ final Object pid = mainMap.get(PROP_PID);
if ( ! (pid instanceof String) ) {
SystemLogger.error("Ignoring configuration in '" + identifier + "' (no service.pid) : " + obj);
} else {
@@ -157,9 +150,9 @@ public class JSONUtil {
final Dictionary<String, Object> properties = new Hashtable<>();
boolean valid = true;
- for(final String mapKey : mainMap.keySet()) {
- final Object value = getValue(mainMap, mapKey);
-
+ for(final Object mapKeyObj : mainMap.keySet()) {
+ final Object value = mainMap.get(mapKeyObj);
+ final String mapKey = mapKeyObj.toString();
if ( mapKey.equals(PROP_PID) ) {
continue;
}
@@ -238,7 +231,7 @@ public class JSONUtil {
* @param contents The contents
* @return The parsed JSON object or {@code null} on failure,
*/
- public static JsonObject parseJSON(final String name, String contents) {
+ public static Map parseJSON(final String name, String contents) {
// minify JSON first (remove comments)
try (final Reader in = new StringReader(contents);
final Writer out = new StringWriter()) {
@@ -249,55 +242,13 @@ public class JSONUtil {
SystemLogger.error("Invalid JSON from " + name);
return null;
}
- try (final JsonReader reader = Json.createReader(new StringReader(contents)) ) {
- final JsonStructure obj = reader.read();
- if ( obj != null && obj.getValueType() == ValueType.OBJECT ) {
- return (JsonObject)obj;
- }
+ final Serializer serializer = new JsonSerializerImpl();
+ try (final Reader reader = new StringReader(contents) ) {
+ return serializer.deserialize(Map.class).from(reader);
+ } catch ( final IOException ioe) {
SystemLogger.error("Invalid JSON from " + name);
+ return null;
}
- return null;
- }
-
- /**
- * Get the value of a JSON property
- * @param root The JSON Object
- * @param key The key in the JSON Obejct
- * @return The value or {@code null}
- */
- public static Object getValue(final JsonObject root, final String key) {
- if ( !root.containsKey(key) ) {
- return null;
- }
- final JsonValue value = root.get(key);
- return getValue(value);
- }
-
- public static Object getValue(final JsonValue value) {
- switch ( value.getValueType() ) {
- // type NULL -> return null
- case NULL : return null;
- // type TRUE or FALSE -> return boolean
- case FALSE : return false;
- case TRUE : return true;
- // type String -> return String
- case STRING : return ((JsonString)value).getString();
- // type Number -> return long or double
- case NUMBER : final JsonNumber num = (JsonNumber)value;
- if (num.isIntegral()) {
- return num.longValue();
- }
- return num.doubleValue();
- // type ARRAY -> return list and call this method for each value
- case ARRAY : final List<Object> array = new ArrayList<>();
- for(final JsonValue x : ((JsonArray)value)) {
- array.add(getValue(x));
- }
- return array;
- // type OBJECT -> return object
- case OBJECT : return value;
- }
- return null;
}
/**
@@ -306,11 +257,11 @@ public class JSONUtil {
* @param root The JSON root object.
* @return JSON array with configurations or {@code null}
*/
- public static List<?> verifyJSON(final String name, final JsonObject root) {
+ public static List<?> verifyJSON(final String name, final Map root) {
if ( root == null ) {
return null;
}
- final Object version = getValue(root, PROP_VERSION);
+ final Object version = root.get(PROP_VERSION);
if ( version != null ) {
final int v = TypeConverter.getConverter().convert(version).defaultValue(-1).to(Integer.class);
@@ -324,7 +275,7 @@ public class JSONUtil {
return null;
}
}
- final Object configs = getValue(root, "configurations");
+ final Object configs = root.get("configurations");
if ( configs == null ) {
// short cut, we just return false as we don't have to process this file
return null;
Modified: felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java?rev=1777637&r1=1777636&r2=1777637&view=diff
==============================================================================
--- felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java (original)
+++ felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java Fri Jan 6 16:21:55 2017
@@ -26,8 +26,7 @@ import static org.junit.Assert.assertTru
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Collection;
-
-import javax.json.JsonObject;
+import java.util.Map;
import org.apache.felix.configurator.impl.json.JSONUtil;
import org.apache.felix.configurator.impl.json.JSONUtilTest;
@@ -105,143 +104,143 @@ public class TypeConverterTest {
@Test public void testSimpleTypeConversions() throws Exception {
final TypeConverter converter = new TypeConverter(null);
- final JsonObject config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
- final JsonObject properties = (JsonObject)config.get("config");
+ final Map config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
+ final Map properties = (Map)config.get("config");
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string"), null) instanceof String);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "boolean"), null) instanceof Boolean);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), null) instanceof Long);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float"), null) instanceof Double);
+ assertTrue(converter.convert(properties.get("string"), null) instanceof String);
+ assertTrue(converter.convert(properties.get("boolean"), null) instanceof Boolean);
+ assertTrue(converter.convert(properties.get("number"), null) instanceof Long);
+ assertTrue(converter.convert(properties.get("float"), null) instanceof Double);
// arrays
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string.array"), null).getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "string.array"), null), 0) instanceof String);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "string.array"), null), 1) instanceof String);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "boolean.array"), null).getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "boolean.array"), null), 0) instanceof Boolean);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "boolean.array"), null), 1) instanceof Boolean);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), null).getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), null), 0) instanceof Long);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), null), 1) instanceof Long);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float.array"), null).getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "float.array"), null), 0) instanceof Double);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "float.array"), null), 1) instanceof Double);
+ assertTrue(converter.convert(properties.get("string.array"), null).getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("string.array"), null), 0) instanceof String);
+ assertTrue(Array.get(converter.convert(properties.get("string.array"), null), 1) instanceof String);
+
+ assertTrue(converter.convert(properties.get("boolean.array"), null).getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("boolean.array"), null), 0) instanceof Boolean);
+ assertTrue(Array.get(converter.convert(properties.get("boolean.array"), null), 1) instanceof Boolean);
+
+ assertTrue(converter.convert(properties.get("number.array"), null).getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), null), 0) instanceof Long);
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), null), 1) instanceof Long);
+
+ assertTrue(converter.convert(properties.get("float.array"), null).getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("float.array"), null), 0) instanceof Double);
+ assertTrue(Array.get(converter.convert(properties.get("float.array"), null), 1) instanceof Double);
}
@Test public void testSimpleTypeConversionsWithTypeHint() throws Exception {
final TypeConverter converter = new TypeConverter(null);
- final JsonObject config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
- final JsonObject properties = (JsonObject)config.get("config");
+ final Map config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
+ final Map properties = (Map)config.get("config");
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string"), "String") instanceof String);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "boolean"), "Boolean") instanceof Boolean);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "boolean"), "boolean") instanceof Boolean);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), "Integer") instanceof Integer);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), "int") instanceof Integer);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), "Long") instanceof Long);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), "long") instanceof Long);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float"), "Double") instanceof Double);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float"), "double") instanceof Double);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float"), "Float") instanceof Float);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float"), "float") instanceof Float);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), "Byte") instanceof Byte);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), "byte") instanceof Byte);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), "Short") instanceof Short);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number"), "short") instanceof Short);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string"), "Character") instanceof Character);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string"), "char") instanceof Character);
+ assertTrue(converter.convert(properties.get("string"), "String") instanceof String);
+ assertTrue(converter.convert(properties.get("boolean"), "Boolean") instanceof Boolean);
+ assertTrue(converter.convert(properties.get("boolean"), "boolean") instanceof Boolean);
+ assertTrue(converter.convert(properties.get("number"), "Integer") instanceof Integer);
+ assertTrue(converter.convert(properties.get("number"), "int") instanceof Integer);
+ assertTrue(converter.convert(properties.get("number"), "Long") instanceof Long);
+ assertTrue(converter.convert(properties.get("number"), "long") instanceof Long);
+ assertTrue(converter.convert(properties.get("float"), "Double") instanceof Double);
+ assertTrue(converter.convert(properties.get("float"), "double") instanceof Double);
+ assertTrue(converter.convert(properties.get("float"), "Float") instanceof Float);
+ assertTrue(converter.convert(properties.get("float"), "float") instanceof Float);
+ assertTrue(converter.convert(properties.get("number"), "Byte") instanceof Byte);
+ assertTrue(converter.convert(properties.get("number"), "byte") instanceof Byte);
+ assertTrue(converter.convert(properties.get("number"), "Short") instanceof Short);
+ assertTrue(converter.convert(properties.get("number"), "short") instanceof Short);
+ assertTrue(converter.convert(properties.get("string"), "Character") instanceof Character);
+ assertTrue(converter.convert(properties.get("string"), "char") instanceof Character);
// arrays
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string.array"), "String[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "string.array"), "String[]"), 0) instanceof String);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "string.array"), "String[]"), 1) instanceof String);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "boolean.array"), "Boolean[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "boolean.array"), "Boolean[]"), 0) instanceof Boolean);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "boolean.array"), "Boolean[]"), 1) instanceof Boolean);
+ assertTrue(converter.convert(properties.get("string.array"), "String[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("string.array"), "String[]"), 0) instanceof String);
+ assertTrue(Array.get(converter.convert(properties.get("string.array"), "String[]"), 1) instanceof String);
+
+ assertTrue(converter.convert(properties.get("boolean.array"), "Boolean[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("boolean.array"), "Boolean[]"), 0) instanceof Boolean);
+ assertTrue(Array.get(converter.convert(properties.get("boolean.array"), "Boolean[]"), 1) instanceof Boolean);
// the following would throw class cast exceptions
- boolean[] a0 = (boolean[])converter.convert(JSONUtil.getValue(properties, "boolean.array"), "boolean[]");
+ boolean[] a0 = (boolean[])converter.convert(properties.get("boolean.array"), "boolean[]");
assertNotNull(a0);
- int[] a1 = (int[])converter.convert(JSONUtil.getValue(properties, "number.array"), "int[]");
+ int[] a1 = (int[])converter.convert(properties.get("number.array"), "int[]");
assertNotNull(a1);
- long[] a2 = (long[])converter.convert(JSONUtil.getValue(properties, "number.array"), "long[]");
+ long[] a2 = (long[])converter.convert(properties.get("number.array"), "long[]");
assertNotNull(a2);
- double[] a3 = (double[])converter.convert(JSONUtil.getValue(properties, "float.array"), "double[]");
+ double[] a3 = (double[])converter.convert(properties.get("float.array"), "double[]");
assertNotNull(a3);
- float[] a4 = (float[])converter.convert(JSONUtil.getValue(properties, "float.array"), "float[]");
+ float[] a4 = (float[])converter.convert(properties.get("float.array"), "float[]");
assertNotNull(a4);
- byte[] a5 = (byte[])converter.convert(JSONUtil.getValue(properties, "number.array"), "byte[]");
+ byte[] a5 = (byte[])converter.convert(properties.get("number.array"), "byte[]");
assertNotNull(a5);
- short[] a6 = (short[])converter.convert(JSONUtil.getValue(properties, "number.array"), "short[]");
+ short[] a6 = (short[])converter.convert(properties.get("number.array"), "short[]");
assertNotNull(a6);
- char[] a7 = (char[])converter.convert(JSONUtil.getValue(properties, "string.array"), "char[]");
+ char[] a7 = (char[])converter.convert(properties.get("string.array"), "char[]");
assertNotNull(a7);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), "Integer[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), "Integer[]"), 0) instanceof Integer);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), "Integer[]"), 1) instanceof Integer);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), "Long[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), "Long[]"), 0) instanceof Long);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), "Long[]"), 1) instanceof Long);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), "Byte[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), "Byte[]"), 0) instanceof Byte);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), "Byte[]"), 1) instanceof Byte);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), "Short[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), "Short[]"), 0) instanceof Short);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "number.array"), "Short[]"), 1) instanceof Short);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float.array"), "Float[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "float.array"), "Float[]"), 0) instanceof Float);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "float.array"), "Float[]"), 1) instanceof Float);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float.array"), "Double[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "float.array"), "Double[]"), 0) instanceof Double);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "float.array"), "Double[]"), 1) instanceof Double);
-
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string.array"), "Character[]").getClass().isArray());
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "string.array"), "Character[]"), 0) instanceof Character);
- assertTrue(Array.get(converter.convert(JSONUtil.getValue(properties, "string.array"), "Character[]"), 1) instanceof Character);
+ assertTrue(converter.convert(properties.get("number.array"), "Integer[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), "Integer[]"), 0) instanceof Integer);
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), "Integer[]"), 1) instanceof Integer);
+
+ assertTrue(converter.convert(properties.get("number.array"), "Long[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), "Long[]"), 0) instanceof Long);
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), "Long[]"), 1) instanceof Long);
+
+ assertTrue(converter.convert(properties.get("number.array"), "Byte[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), "Byte[]"), 0) instanceof Byte);
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), "Byte[]"), 1) instanceof Byte);
+
+ assertTrue(converter.convert(properties.get("number.array"), "Short[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), "Short[]"), 0) instanceof Short);
+ assertTrue(Array.get(converter.convert(properties.get("number.array"), "Short[]"), 1) instanceof Short);
+
+ assertTrue(converter.convert(properties.get("float.array"), "Float[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("float.array"), "Float[]"), 0) instanceof Float);
+ assertTrue(Array.get(converter.convert(properties.get("float.array"), "Float[]"), 1) instanceof Float);
+
+ assertTrue(converter.convert(properties.get("float.array"), "Double[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("float.array"), "Double[]"), 0) instanceof Double);
+ assertTrue(Array.get(converter.convert(properties.get("float.array"), "Double[]"), 1) instanceof Double);
+
+ assertTrue(converter.convert(properties.get("string.array"), "Character[]").getClass().isArray());
+ assertTrue(Array.get(converter.convert(properties.get("string.array"), "Character[]"), 0) instanceof Character);
+ assertTrue(Array.get(converter.convert(properties.get("string.array"), "Character[]"), 1) instanceof Character);
}
@SuppressWarnings("unchecked")
@Test public void testCollectionTypeConversion() throws Exception {
final TypeConverter converter = new TypeConverter(null);
- final JsonObject config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
- final JsonObject properties = (JsonObject)config.get("config");
+ final Map config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
+ final Map properties = (Map)config.get("config");
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string.array"), "Collection<String>") instanceof Collection<?>);
- assertTrue(((Collection<String>)converter.convert(JSONUtil.getValue(properties, "string.array"), "Collection<String>")).iterator().next() instanceof String);
+ assertTrue(converter.convert(properties.get("string.array"), "Collection<String>") instanceof Collection<?>);
+ assertTrue(((Collection<String>)converter.convert(properties.get("string.array"), "Collection<String>")).iterator().next() instanceof String);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), "Collection<Integer>") instanceof Collection<?>);
- assertTrue(((Collection<Integer>)converter.convert(JSONUtil.getValue(properties, "number.array"), "Collection<Integer>")).iterator().next() instanceof Integer);
+ assertTrue(converter.convert(properties.get("number.array"), "Collection<Integer>") instanceof Collection<?>);
+ assertTrue(((Collection<Integer>)converter.convert(properties.get("number.array"), "Collection<Integer>")).iterator().next() instanceof Integer);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), "Collection<Long>") instanceof Collection<?>);
- assertTrue(((Collection<Long>)converter.convert(JSONUtil.getValue(properties, "number.array"), "Collection<Long>")).iterator().next() instanceof Long);
+ assertTrue(converter.convert(properties.get("number.array"), "Collection<Long>") instanceof Collection<?>);
+ assertTrue(((Collection<Long>)converter.convert(properties.get("number.array"), "Collection<Long>")).iterator().next() instanceof Long);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float.array"), "Collection<Float>") instanceof Collection<?>);
- assertTrue(((Collection<Float>)converter.convert(JSONUtil.getValue(properties, "float.array"), "Collection<Float>")).iterator().next() instanceof Float);
+ assertTrue(converter.convert(properties.get("float.array"), "Collection<Float>") instanceof Collection<?>);
+ assertTrue(((Collection<Float>)converter.convert(properties.get("float.array"), "Collection<Float>")).iterator().next() instanceof Float);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "float.array"), "Collection<Double>") instanceof Collection<?>);
- assertTrue(((Collection<Double>)converter.convert(JSONUtil.getValue(properties, "float.array"), "Collection<Double>")).iterator().next() instanceof Double);
+ assertTrue(converter.convert(properties.get("float.array"), "Collection<Double>") instanceof Collection<?>);
+ assertTrue(((Collection<Double>)converter.convert(properties.get("float.array"), "Collection<Double>")).iterator().next() instanceof Double);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), "Collection<Short>") instanceof Collection<?>);
- assertTrue(((Collection<Short>)converter.convert(JSONUtil.getValue(properties, "number.array"), "Collection<Short>")).iterator().next() instanceof Short);
+ assertTrue(converter.convert(properties.get("number.array"), "Collection<Short>") instanceof Collection<?>);
+ assertTrue(((Collection<Short>)converter.convert(properties.get("number.array"), "Collection<Short>")).iterator().next() instanceof Short);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "number.array"), "Collection<Byte>") instanceof Collection<?>);
- assertTrue(((Collection<Byte>)converter.convert(JSONUtil.getValue(properties, "number.array"), "Collection<Byte>")).iterator().next() instanceof Byte);
+ assertTrue(converter.convert(properties.get("number.array"), "Collection<Byte>") instanceof Collection<?>);
+ assertTrue(((Collection<Byte>)converter.convert(properties.get("number.array"), "Collection<Byte>")).iterator().next() instanceof Byte);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "string.array"), "Collection<Character>") instanceof Collection<?>);
- assertTrue(((Collection<Character>)converter.convert(JSONUtil.getValue(properties, "string.array"), "Collection<Character>")).iterator().next() instanceof Character);
+ assertTrue(converter.convert(properties.get("string.array"), "Collection<Character>") instanceof Collection<?>);
+ assertTrue(((Collection<Character>)converter.convert(properties.get("string.array"), "Collection<Character>")).iterator().next() instanceof Character);
- assertTrue(converter.convert(JSONUtil.getValue(properties, "boolean.array"), "Collection<Boolean>") instanceof Collection<?>);
- assertTrue(((Collection<Boolean>)converter.convert(JSONUtil.getValue(properties, "boolean.array"), "Collection<Boolean>")).iterator().next() instanceof Boolean);
+ assertTrue(converter.convert(properties.get("boolean.array"), "Collection<Boolean>") instanceof Collection<?>);
+ assertTrue(((Collection<Boolean>)converter.convert(properties.get("boolean.array"), "Collection<Boolean>")).iterator().next() instanceof Boolean);
}
}
Modified: felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java?rev=1777637&r1=1777636&r2=1777637&view=diff
==============================================================================
--- felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java (original)
+++ felix/trunk/configurator/src/test/java/org/apache/felix/configurator/impl/json/JSONUtilTest.java Fri Jan 6 16:21:55 2017
@@ -28,8 +28,7 @@ import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
import java.util.List;
-
-import javax.json.JsonObject;
+import java.util.Map;
import org.apache.felix.configurator.impl.TypeConverter;
import org.apache.felix.configurator.impl.model.ConfigurationFile;
@@ -62,29 +61,29 @@ public class JSONUtilTest {
@SuppressWarnings("unchecked")
@Test public void testTypes() throws Exception {
- final JsonObject config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
- final JsonObject properties = (JsonObject)config.get("config");
+ final Map config = JSONUtil.parseJSON("a", JSONUtilTest.readJSON("json/simple-types.json"));
+ final Map properties = (Map)config.get("config");
- assertTrue(JSONUtil.getValue(properties, "string") instanceof String);
- assertTrue(JSONUtil.getValue(properties, "boolean") instanceof Boolean);
- assertTrue(JSONUtil.getValue(properties, "number") instanceof Long);
- assertTrue(JSONUtil.getValue(properties, "float") instanceof Double);
+ assertTrue(properties.get("string") instanceof String);
+ assertTrue(properties.get("boolean") instanceof Boolean);
+ assertTrue(properties.get("number") instanceof Long);
+ assertTrue(properties.get("float") instanceof Double);
// arrays
- assertTrue(JSONUtil.getValue(properties, "string.array") instanceof List<?>);
- assertTrue(((List<Object>)JSONUtil.getValue(properties, "string.array")).get(0) instanceof String);
- assertTrue(((List<Object>)JSONUtil.getValue(properties, "string.array")).get(1) instanceof String);
-
- assertTrue((List<Object>)JSONUtil.getValue(properties, "boolean.array") instanceof List<?>);
- assertTrue(((List<Object>)JSONUtil.getValue(properties, "boolean.array")).get(0) instanceof Boolean);
- assertTrue(((List<Object>)JSONUtil.getValue(properties, "boolean.array")).get(1) instanceof Boolean);
-
- assertTrue((List<Object>)JSONUtil.getValue(properties, "number.array") instanceof List<?>);
- assertTrue(((List<Object>)JSONUtil.getValue(properties, "number.array")).get(0) instanceof Long);
- assertTrue(((List<Object>)JSONUtil.getValue(properties, "number.array")).get(1) instanceof Long);
-
- assertTrue((List<Object>)JSONUtil.getValue(properties, "float.array") instanceof List<?>);
- assertTrue(((List<Object>)JSONUtil.getValue(properties, "float.array")).get(0) instanceof Double);
- assertTrue(((List<Object>)JSONUtil.getValue(properties, "float.array")).get(1) instanceof Double);
+ assertTrue(properties.get("string.array") instanceof List<?>);
+ assertTrue(((List<Object>)properties.get("string.array")).get(0) instanceof String);
+ assertTrue(((List<Object>)properties.get("string.array")).get(1) instanceof String);
+
+ assertTrue((List<Object>)properties.get("boolean.array") instanceof List<?>);
+ assertTrue(((List<Object>)properties.get("boolean.array")).get(0) instanceof Boolean);
+ assertTrue(((List<Object>)properties.get("boolean.array")).get(1) instanceof Boolean);
+
+ assertTrue((List<Object>)properties.get("number.array") instanceof List<?>);
+ assertTrue(((List<Object>)properties.get("number.array")).get(0) instanceof Long);
+ assertTrue(((List<Object>)properties.get("number.array")).get(1) instanceof Long);
+
+ assertTrue((List<Object>)properties.get("float.array") instanceof List<?>);
+ assertTrue(((List<Object>)properties.get("float.array")).get(0) instanceof Double);
+ assertTrue(((List<Object>)properties.get("float.array")).get(1) instanceof Double);
}
}
\ No newline at end of file