* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
* See the License for the specific language governing permissions and
* limitations under the License.
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
import java.io.IOException;
import java.io.Reader;
+import java.io.UncheckedIOException;
import java.util.*;
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+ private JSONUtil() {}
+
public static <T> T fromJson(String json, Class<T> clazz) {
try {
return OBJECT_MAPPER.readValue(json, clazz);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
}
try {
return OBJECT_MAPPER.readValue(reader, clazz);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
}
try {
return OBJECT_MAPPER.writeValueAsString(object);
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
}
- public static Map<String,String> extractPlainValues(String json, String ... names) {
- if (null == names) return Collections.emptyMap();
- Map<String,String> values = new HashMap<>();
+ public static Map<String, String> extractPlainValues(String json, String... names) {
+ if (null == names) {
+ return Collections.emptyMap();
+ }
+ Map<String, String> values = new HashMap<>();
try {
final JsonNode jsonNode = OBJECT_MAPPER.readTree(json);
for (String name : names) {
values.put(name, jsonNode.path(name).asText());
}
} catch (IOException e) {
- throw new RuntimeException(e);
+ throw new UncheckedIOException(e);
}
return values;
}
-
-
-
-
}