diff options
Diffstat (limited to 'gson/src/main/java/org/onap/policy/common/gson/internal')
5 files changed, 44 insertions, 44 deletions
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 174b4912..af4a746c 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -24,11 +24,12 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; import com.google.gson.reflect.TypeToken; +import com.google.re2j.Pattern; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.function.Supplier; -import java.util.regex.Pattern; +import lombok.Getter; import org.onap.policy.common.gson.annotation.GsonJsonProperty; /** @@ -49,6 +50,7 @@ public class Adapter { /** * Name of the property within the json structure containing the item. */ + @Getter private final String propName; /** @@ -69,6 +71,7 @@ public class Adapter { /** * Name of the item being lifted - used when throwing exceptions. */ + @Getter private final String fullName; /** @@ -83,7 +86,10 @@ public class Adapter { this.gson = gson; this.fullName = getQualifiedName(field); - field.setAccessible(true); + /* + * Turning off sonar, as this is required for emulation of "jackson". + */ + field.setAccessible(true); // NOSONAR } /** @@ -100,7 +106,10 @@ public class Adapter { this.gson = gson; this.fullName = getQualifiedName(accessor); - accessor.setAccessible(true); + /* + * Turning off sonar, as this is required for emulation of "jackson". + */ + accessor.setAccessible(true); // NOSONAR } /** @@ -121,8 +130,8 @@ public class Adapter { ConvInfo wtr = writer; - @SuppressWarnings("rawtypes") - TypeAdapter conv = (wtr.clazz == clazz ? wtr.getConverter() : gson.getAdapter(clazz)); + TypeAdapter<Object> conv = + (wtr.clazz == clazz ? wtr.getConverter() : (TypeAdapter<Object>) gson.getAdapter(clazz)); return conv.toJsonTree(object); } @@ -137,14 +146,6 @@ public class Adapter { return reader.getConverter().fromJsonTree(tree); } - public final String getPropName() { - return propName; - } - - public final String getFullName() { - return fullName; - } - /** * Makes an error message, appending the item's full name to the message prefix. * @@ -310,36 +311,33 @@ public class Adapter { /** * Type on which the converter works. */ - @SuppressWarnings("rawtypes") - private TypeToken type; + private TypeToken<?> type; /** * Class of object on which the converter works. */ - @SuppressWarnings("rawtypes") - private Class clazz; + private Class<?> clazz; /** * Converter to use, initialized lazily. */ - @SuppressWarnings("rawtypes") - private TypeAdapter conv = null; + private TypeAdapter<Object> conv = null; /** * Constructs the object. * * @param type type of object to be converted */ - public ConvInfo(@SuppressWarnings("rawtypes") TypeToken type) { + public ConvInfo(TypeToken<?> type) { this.type = type; this.clazz = type.getRawType(); } - @SuppressWarnings({"rawtypes", "unchecked"}) - public final TypeAdapter getConverter() { + @SuppressWarnings("unchecked") + public final TypeAdapter<Object> getConverter() { if (conv == null) { // race condition here, but it's ok to overwrite a previous value - this.conv = gson.getAdapter(type); + this.conv = (TypeAdapter<Object>) gson.getAdapter(type); } return conv; 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 ef4eaae3..954d3f4c 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 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. @@ -30,6 +30,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import lombok.Getter; import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; @@ -79,23 +80,16 @@ public class ClassWalker { * Method having {@link GsonJsonAnyGetter} annotation. Overwritten as new "any-getters" * are identified. */ + @Getter private Method anyGetter = null; /** * Method having {@link GsonJsonAnySetter} annotation. Overwritten as new "any-setters" * are identified. */ + @Getter private Method anySetter = null; - - public Method getAnyGetter() { - return anyGetter; - } - - public Method getAnySetter() { - return anySetter; - } - /** * Gets the names of input properties that are not being ignored. * diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/FieldDeserializer.java b/gson/src/main/java/org/onap/policy/common/gson/internal/FieldDeserializer.java index 14a432d1..123b0195 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/FieldDeserializer.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/FieldDeserializer.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 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. @@ -49,7 +49,10 @@ public class FieldDeserializer extends Adapter implements Deserializer { this.field = field; - field.setAccessible(true); + /* + * Turning off sonar, as this is required for emulation of "jackson". + */ + field.setAccessible(true); // NOSONAR } @Override @@ -62,7 +65,10 @@ public class FieldDeserializer extends Adapter implements Deserializer { Object value = fromJsonTree(jsonEl); try { - field.set(target, value); + /* + * Turning off sonar, as this is required for emulation of "jackson". + */ + field.set(target, value); // NOSONAR } catch (IllegalArgumentException | IllegalAccessException e) { throw new JsonParseException(makeError(SET_ERR), e); diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/FieldSerializer.java b/gson/src/main/java/org/onap/policy/common/gson/internal/FieldSerializer.java index 1c9d8b37..348ef5a0 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/FieldSerializer.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/FieldSerializer.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 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. @@ -50,7 +50,10 @@ public class FieldSerializer extends Adapter implements Serializer { this.field = field; - field.setAccessible(true); + /* + * Turning off sonar, as this is required for emulation of "jackson". + */ + field.setAccessible(true); // NOSONAR } @Override diff --git a/gson/src/main/java/org/onap/policy/common/gson/internal/JacksonTypeAdapter.java b/gson/src/main/java/org/onap/policy/common/gson/internal/JacksonTypeAdapter.java index 1171fd4d..34d61f47 100644 --- a/gson/src/main/java/org/onap/policy/common/gson/internal/JacksonTypeAdapter.java +++ b/gson/src/main/java/org/onap/policy/common/gson/internal/JacksonTypeAdapter.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 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. @@ -22,7 +22,6 @@ package org.onap.policy.common.gson.internal; import com.google.gson.Gson; import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; @@ -78,7 +77,7 @@ public class JacksonTypeAdapter<T> extends TypeAdapter<T> { JsonElement tree = delegate.toJsonTree(value); if (tree.isJsonObject()) { - JsonObject jsonObj = tree.getAsJsonObject(); + var jsonObj = tree.getAsJsonObject(); // serialize each item from the value into the target tree for (Serializer serializer : serializers) { @@ -92,10 +91,10 @@ public class JacksonTypeAdapter<T> extends TypeAdapter<T> { @Override public T read(JsonReader in) throws IOException { JsonElement tree = elementAdapter.read(in); - T object = delegate.fromJsonTree(tree); + var object = delegate.fromJsonTree(tree); if (tree.isJsonObject()) { - JsonObject jsonObj = tree.getAsJsonObject(); + var jsonObj = tree.getAsJsonObject(); // deserialize each item from the tree into the target object for (Deserializer dser : deserializers) { |