1

I have a Enum attribute in a class.

private ValueType valueType;

ValueType is a ENUM as below.

public enum ValueType {

    INT, FLOAT, STRING, BOOLEAN, ENUM, DATE, CONSTANT
}

I have a jason request as below. As you can see in the json request, "valueType": "string" (small s), so, I get the below error. So, how to validate the ENUM attribute?

{
  "payload": {
    "id": "Test_snapshot_1",
    "questionId": "Test_snapshot_1",
    "name": "Test_snapshot",
    "valueType": "string",
    "displayType": "heading1",
    "submitOnChange": true,
    "label": "Thank you!",
    "defaultValue": "Thank you!",
    "minValue": null,
    "maxValue": null,
    "minLength": null,
    "maxLength": null,
    "required": null,
    "helpText": null,
    "enumValues": null,
    "answerToOptionalQuestions": null,

  }
}

ERROR I am Getting as below

{


"status": "BAD_REQUEST",
  "errors": [
    {
      "code": "400",
      "description": "Can not construct instance of com.services.cf.common.dto.ValueType from String value 'string': value not one of declared Enum instance names\n at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@7338f52c; line: 6, column: 28] (through reference chain: com.platform.soa.common.service.wrappers.ServiceRequest[\"payload\"]->com.services.cf.common.dto.Question[\"valueType\"])",
      "info": "org.codehaus.jackson.map.JsonMappingException: Can not construct instance of com.services.cf.common.dto.ValueType from String value 'string': value not one of declared Enum instance names\\n at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@7338f52c; line: 6, column: 28] (through reference chain: com.platform.soa.common.valueTypeservice.wrappers.ServiceRequest[\\\"payload\\\"]->com.services.cf.common.dto.Question[\\\"\\\"])\\n\\tat org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)\\n\\tat org.codehaus.jackson.map.deser.StdDeserializationContext.weirdStringException(StdDeserializationContext.java:243)\\n",
      "severity": "ERROR",
      "category": "REQUEST",
      "errorIdentifiers": {
        "entry": []
      }
    }
  ],
  "payload": null
}
Abhash Upadhyaya
  • 717
  • 14
  • 34
Subrat007
  • 11
  • 1

0 Answers0