diff options
Diffstat (limited to 'gson/src')
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 bb8672bb..65baaee4 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 @@ -115,8 +115,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); } @@ -304,29 +305,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 { /** |