From 7917f4d2f2c5066d7e5ba7c94f8cb4ec1685cfec Mon Sep 17 00:00:00 2001 From: jbertram Date: Mon, 1 Aug 2016 10:07:50 -0500 Subject: [PATCH] ARTEMIS-565 JSON fixes --- .../activemq/artemis/api/core/JsonUtil.java | 37 +++++++++++++++++-- .../management/ManagementHelperTest.java | 4 +- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java index 62bb8713ff..0343a64978 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/JsonUtil.java @@ -126,6 +126,21 @@ public final class JsonUtil { else if (innerVal instanceof JsonString) { innerVal = ((JsonString)innerVal).getString(); } + else if (innerVal == JsonValue.FALSE) { + innerVal = Boolean.FALSE; + } + else if (innerVal == JsonValue.TRUE) { + innerVal = Boolean.TRUE; + } + else if (innerVal instanceof JsonNumber) { + JsonNumber jsonNumber = (JsonNumber)innerVal; + if (jsonNumber.isIntegral()) { + innerVal = jsonNumber.longValue(); + } + else { + innerVal = jsonNumber.doubleValue(); + } + } else if (innerVal instanceof JsonObject) { Map innerMap = new HashMap<>(); JsonObject o = (JsonObject) innerVal; @@ -135,10 +150,6 @@ public final class JsonUtil { } innerVal = innerMap; } - else if (innerVal instanceof JsonNumber) { - JsonNumber jsonNumber = (JsonNumber)innerVal; - innerVal = jsonNumber.longValue(); - } if (CompositeData.class.getName().equals(key)) { Object[] data = (Object[]) innerVal; CompositeData[] cds = new CompositeData[data.length]; @@ -155,6 +166,24 @@ public final class JsonUtil { array[i] = map; } + else if (val instanceof JsonString) { + array[i] = ((JsonString)val).getString(); + } + else if (val == JsonValue.FALSE) { + array[i] = Boolean.FALSE; + } + else if (val == JsonValue.TRUE) { + array[i] = Boolean.TRUE; + } + else if (val instanceof JsonNumber) { + JsonNumber jsonNumber = (JsonNumber)val; + if (jsonNumber.isIntegral()) { + array[i] = jsonNumber.longValue(); + } + else { + array[i] = jsonNumber.doubleValue(); + } + } else { if (val == JsonValue.NULL) { array[i] = null; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementHelperTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementHelperTest.java index 9fb95e7af6..8cc0f99d1f 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementHelperTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementHelperTest.java @@ -69,7 +69,7 @@ public class ManagementHelperTest extends Assert { String resource = RandomUtil.randomString(); String operationName = RandomUtil.randomString(); - int i = RandomUtil.randomInt(); + long i = RandomUtil.randomInt(); String s = RandomUtil.randomString(); double d = RandomUtil.randomDouble(); boolean b = RandomUtil.randomBoolean(); @@ -192,7 +192,7 @@ public class ManagementHelperTest extends Assert { ManagementHelperTest.log.info("val1 type is " + Arrays.toString(val1)); String key2 = RandomUtil.randomString(); - Integer[] val2 = new Integer[]{1, 2, 3, 4, 5}; + Long[] val2 = new Long[]{1L, 2L, 3L, 4L, 5L}; ManagementHelperTest.log.info("val2 type is " + Arrays.toString(val2));