diff options
author | Jim Hahn <jrh3@att.com> | 2019-02-12 10:50:06 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-02-12 10:53:53 -0500 |
commit | 0d3b95a4e1dc8059a6eb5b1f98c3f7f41f09b151 (patch) | |
tree | c3c9b3c859115d729b2cc6d8f68e6bdada90f9dc /gson/src/main/java/org | |
parent | 13ca63c40a379f95539cb4882ec2b645cd0c2a48 (diff) |
Fix sonar issues in gson superclasses
Fixing some of the issues necessitated the use of generic/raw types.
Removed version from assertj in pom.
Removed trailing spaces.
Change-Id: I76e0a05ca06c103ccc876675be04a4ab5e4de5ea
Issue-ID: POLICY-1428
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'gson/src/main/java/org')
5 files changed, 22 insertions, 14 deletions
diff --git a/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java b/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java index 2112c97c..66475e3e 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java +++ b/gson/src/main/java/org/onap/policy/common/gson/GsonMessageBodyHandler.java @@ -80,7 +80,7 @@ public class GsonMessageBodyHandler implements MessageBodyReader<Object>, Messag @Override public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) - throws IOException, WebApplicationException { + throws IOException { try (OutputStreamWriter writer = new OutputStreamWriter(entityStream, StandardCharsets.UTF_8)) { Type jsonType = (type.equals(genericType) ? type : genericType); @@ -107,8 +107,11 @@ public class GsonMessageBodyHandler implements MessageBodyReader<Object>, Messag String subtype = mediaType.getSubtype(); - return "json".equalsIgnoreCase(subtype) || subtype.endsWith("+json") || "javascript".equals(subtype) - || "x-javascript".equals(subtype) || "x-json".equals(subtype); + if ("json".equalsIgnoreCase(subtype) || "javascript".equals(subtype)) { + return true; + } + + return subtype.endsWith("+json") || "x-json".equals(subtype) || "x-javascript".equals(subtype); } @Override diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java index b4ef53f7..94091c79 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Adapter.java @@ -116,8 +116,9 @@ public class Adapter { } ConvInfo wtr = writer; - TypeAdapter<Object> conv = - (TypeAdapter<Object>) (wtr.clazz == clazz ? wtr.getConverter() : gson.getAdapter(clazz)); + + @SuppressWarnings("rawtypes") + TypeAdapter conv = (wtr.clazz == clazz ? wtr.getConverter() : gson.getAdapter(clazz)); return conv.toJsonTree(object); } @@ -305,29 +306,33 @@ public class Adapter { /** * Type on which the converter works. */ - private TypeToken<?> type; + @SuppressWarnings("rawtypes") + private TypeToken type; /** * Class of object on which the converter works. */ - private Class<?> clazz; + @SuppressWarnings("rawtypes") + private Class clazz; /** * Converter to use, initialized lazily. */ - private volatile TypeAdapter<?> conv = null; + @SuppressWarnings("rawtypes") + private volatile TypeAdapter conv = null; /** * Constructs the object. * * @param type type of object to be converted */ - public ConvInfo(TypeToken<?> type) { + public ConvInfo(@SuppressWarnings("rawtypes") TypeToken type) { this.type = type; this.clazz = type.getRawType(); } - public final TypeAdapter<?> getConverter() { + @SuppressWarnings({"rawtypes", "unchecked"}) + public final TypeAdapter getConverter() { if (conv == null) { // race condition here, but it's ok to overwrite a previous value this.conv = gson.getAdapter(type); diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java b/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java index e985d98a..89e4f89d 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/ClassWalker.java @@ -122,7 +122,7 @@ public class ClassWalker { * @return the property names having a non-null value */ private List<String> getNonNull(Map<String, Object> props) { - List<String> lst = new ArrayList<String>(props.size()); + List<String> lst = new ArrayList<>(props.size()); for (Entry<String, Object> ent : props.entrySet()) { if (ent.getValue() != null) { @@ -162,7 +162,7 @@ public class ClassWalker { */ @SuppressWarnings("unchecked") private <T> List<T> getProps(Class<T> clazz, Collection<Object> values) { - List<T> lst = new ArrayList<T>(values.size()); + List<T> lst = new ArrayList<>(values.size()); for (Object val : values) { if (val != null && val.getClass() == clazz) { diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Deserializer.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Deserializer.java index f2975860..4bf6e0c3 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/Deserializer.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Deserializer.java @@ -25,10 +25,9 @@ import com.google.gson.JsonObject; /** * Super class of all de-serializers. */ +@FunctionalInterface public interface Deserializer { - String INVOKE_ERR = "cannot invoke method to deserialize: "; - /** * Gets an value from a tree, converts it, and puts it into a target object. * diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/Serializer.java b/gson/src/main/java/org/onap/policy/common/gson/internal/Serializer.java index 2e2782ad..254a5fe7 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/Serializer.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/Serializer.java @@ -25,6 +25,7 @@ import com.google.gson.JsonObject; /** * Super class of all serializers. */ +@FunctionalInterface public interface Serializer { /** |