summaryrefslogtreecommitdiffstats
path: root/common-parameters/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-06-01 10:18:13 -0400
committerJim Hahn <jrh3@att.com>2021-06-01 10:20:05 -0400
commit8bec395a3d4ddff8bd0daca685f3e2162a9b5193 (patch)
treeff412a95747101f66c6fea34fa2bc9c75c0e8a14 /common-parameters/src/main
parent3da8ab1419980bf747214fe164659568a428cb0f (diff)
Validator should report serialized field name
The validator reports field names as they appear in the class rather than as they appear on the wire, which may be confusing to the client. Modified the code to use the serialized name instead. Note: this will require tweaks to some junits in some of the other policy repos. Issue-ID: POLICY-3333 Change-Id: I867dafdc87cd78dec3d3c6fe0236a744284314a3 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'common-parameters/src/main')
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java
index 51c5d57f..d441c286 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/FieldValidator.java
@@ -20,6 +20,7 @@
package org.onap.policy.common.parameters;
+import com.google.gson.annotations.SerializedName;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedParameterizedType;
import java.lang.reflect.AnnotatedType;
@@ -58,6 +59,11 @@ public class FieldValidator extends ValueValidator {
private final Field field;
/**
+ * Name of the field when serialized (i.e., as the client would know it).
+ */
+ private final String serializedName;
+
+ /**
* Method to retrieve the field's value.
*/
private Method accessor;
@@ -76,9 +82,13 @@ public class FieldValidator extends ValueValidator {
String fieldName = field.getName();
if (fieldName.contains("$")) {
+ serializedName = fieldName;
return;
}
+ SerializedName serAnnot = field.getAnnotation(SerializedName.class);
+ serializedName = (serAnnot != null ? serAnnot.value() : fieldName);
+
validator.addValidators(this);
addListValidator(validator);
addMapValidator(validator);
@@ -184,7 +194,7 @@ public class FieldValidator extends ValueValidator {
// get the value
Object value = getValue(object, accessor);
- validateValue(result, field.getName(), value);
+ validateValue(result, serializedName, value);
}
/**