aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-04-13 15:31:48 +0000
committerJim Hahn <jrh3@att.com>2021-04-13 15:31:48 +0000
commit1155833a3d4e271f495e0ca40ea591919aa11b78 (patch)
treead31fe3f008904e20e72536bfb7432040ede19cc /utils/src
parent04623fef95f2b164d79ad48de2ef3708d02eda80 (diff)
Revert "Modify StandardCoder to handle empty source"
This reverts commit 04623fef95f2b164d79ad48de2ef3708d02eda80. Reason for revert: prefer consistency with gson Issue-ID: POLICY-3172 Change-Id: Ic2501abcc68ec1186142a7e520e7985c43fd3315 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'utils/src')
-rw-r--r--utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java27
-rw-r--r--utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java35
2 files changed, 7 insertions, 55 deletions
diff --git a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
index 3b4f3c23..7f5e3b85 100644
--- a/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
+++ b/utils/src/main/java/org/onap/policy/common/utils/coder/StandardCoder.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,7 +40,6 @@ import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
-import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.gson.DoubleConverter;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
@@ -342,17 +341,8 @@ public class StandardCoder implements Coder {
* @param json json string to be decoded
* @param clazz class of object to be decoded
* @return the object represented by the given json string
- * @throws CoderException if the source is empty
*/
- protected <T> T fromJson(String json, Class<T> clazz) throws CoderException {
- if (json == null) {
- return null;
- }
-
- if (StringUtils.isBlank(json)) {
- throw new CoderException("source string is empty");
- }
-
+ protected <T> T fromJson(String json, Class<T> clazz) {
return convertFromDouble(clazz, gson.fromJson(json, clazz));
}
@@ -362,16 +352,9 @@ public class StandardCoder implements Coder {
* @param source source from which to read the json string to be decoded
* @param clazz class of object to be decoded
* @return the object represented by the given json string
- * @throws CoderException if the source is empty
*/
- protected <T> T fromJson(Reader source, Class<T> clazz) throws CoderException {
- T object = gson.fromJson(source, clazz);
-
- if (object == null) {
- throw new CoderException("source is empty");
- }
-
- return convertFromDouble(clazz, object);
+ protected <T> T fromJson(Reader source, Class<T> clazz) {
+ return convertFromDouble(clazz, gson.fromJson(source, clazz));
}
/**
diff --git a/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java b/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java
index be588a40..a468f0b4 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
package org.onap.policy.common.utils.coder;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -264,8 +263,6 @@ public class StandardCoderTest {
@Test
public void testToJsonTree_testFromJsonJsonElementClassT() throws Exception {
- assertThat(coder.fromJson((JsonElement) null, MyMap.class)).isNull();
-
MyMap map = new MyMap();
map.props = new LinkedHashMap<>();
map.props.put("jel keyA", "jel valueA");
@@ -281,34 +278,6 @@ public class StandardCoderTest {
}
@Test
- public void testFromJsonStringClassT() throws Exception {
- assertThat(coder.fromJson((String) null, MyMap.class)).isNull();
-
- String json = "{'props': {'str keyA': 'str valueA', 'str keyB':'str valueB'}}".replace('\'', '"');
-
- Object result = coder.fromJson(json, MyMap.class);
-
- assertNotNull(result);
- assertEquals("{str keyA=str valueA, str keyB=str valueB}", result.toString());
-
- assertThatThrownBy(() -> coder.fromJson("", MyMap.class)).isInstanceOf(CoderException.class)
- .hasMessageContaining("empty");
- }
-
- @Test
- public void testFromJsonReaderClassT() throws Exception {
- String json = "{'props': {'str keyA': 'str valueA', 'str keyB':'str valueB'}}".replace('\'', '"');
-
- Object result = coder.fromJson(new StringReader(json), MyMap.class);
-
- assertNotNull(result);
- assertEquals("{str keyA=str valueA, str keyB=str valueB}", result.toString());
-
- assertThatThrownBy(() -> coder.fromJson(new StringReader(""), MyMap.class)).isInstanceOf(CoderException.class)
- .hasMessageContaining("empty");
- }
-
- @Test
public void testConvertFromDouble() throws Exception {
String text = "[listA, {keyA=100}, 200]";
assertEquals(text, coder.decode(text, Object.class).toString());