0

I have upgraded my ant build project from Java 6 to Java 8, Weblogic 10 to weblogic 12c and from spring 3 to Spring 5. I have upgraded my jackson-all-1.9.10.jar to Jackson jars 2.14.1. I have deployed the code in weblogic 12c. When i do soap request for my service,

I face issue when i give my soap request. Below is my soap request

        "marketSelection" : [{
        "splitStartDate" : "2021-08-16",
        "splitEndDate" : "2021-08-16",
        "dayOfWeek" : 1,   
        "pointOfSale" : "GB",
        "cabinCode" : "M",
        "interventionDetails" : {
            "forecastType" : "E",
            "specialEventReason" : "Christmas 2020",
            "classDetails" : [ {
                "classCode" : "H",
                "nsd" : "10.0",
                "fop" : "8"
            },
            {
                "classCode" : "K",
                "nsd" : "5.0",
                "fop" : "5"
            }]
        }
    }]

My Deserializer  

public class ForecastTypeDeserializer extends JsonDeserializer<ForecastType>
{
   @Override
   public ForecastType deserialize(JsonParser parser, DeserializationContext context) throws IOException,
      JsonProcessingException
   {
      String jsonText = parser.getText();
      ForecastType forecastType = ForecastType.BASE;
      if(ForecastType.BASE.getValue().equals(jsonText))
      {
         forecastType = ForecastType.BASE;
      }
      else if(ForecastType.OUTLIER.getValue().equals(jsonText))
      {
         forecastType = ForecastType.OUTLIER;
      }
      else if(ForecastType.SPECIAL_EVENT.getValue().equals(jsonText))
      {
         forecastType = ForecastType.SPECIAL_EVENT;
      }
      else
      {
         throw new JsonMappingException("Invalid ForecastType [" + parser.getText() + "]");
      }
      return forecastType;
   }
}

ForecastType enum class

public enum ForecastType
{
   BASE("B"),
   OUTLIER("O"),
   SPECIAL_EVENT("E");
   private final String name;
   private final String value;
   private ForecastType(String forecastType)
   {
      this.name = name();
      this.value = forecastType;
   }
   public String getName()
   {
      return name;
   }
   public String getValue()
   {
      return value;
   }
}

Response for the request {"error":{"code":"UNEXPECTED_TECHNICAL_EXCEPTION","message":"JSON parse error: Cannot deserialize value of type \nsdandfopv01.ForecastType` from String \"E\": not one of the values accepted for Enum class: [OUTLIER, BASE, SPECIAL_EVENT]; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `com.ba.schema.revman.dmdfcstrestservicev01.nsdandfopv01.ForecastType` from String \"E\": not one of the values accepted for Enum class: [OUTLIER, BASE, SPECIAL_EVENT]\n at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 488] (through reference chain: nsdandfopv01.QueueApiNsdAndFopUpdateRequest[\"marketSelection\"]->java.util.ArrayList[0]->nsdandfopv01.MarketSelection[\"interventionDetails\"]->nsdandfopv01.InterventionDetails[\"forecastType\"])","description":"[Ljava.lang.StackTraceElement;@2eb0fb6d","validationErrors":null}}`
Can you please help me resolve this.

I have tried all the solutions like 

1. 
`public enum ForecastType
{
   BASE("B"),
   OUTLIER("O"),
   SPECIAL_EVENT("E");
   private final String name;
   private final String value;
   private ForecastType(String forecastType)
   {
      this.name = name();
      this.value = forecastType;
   }
   public String getName()
   {
      return name;
   }
   @JsonProperty("value")
   public String getValue()
   {
      return value;
   }
   private static Map<String, ForecastType> FORMAT_MAP = Stream
            .of(ForecastType.values())
            .collect(Collectors.toMap(s -> s.value, Function.identity()));
   @JsonCreator // This is the factory method and must be static
   public static ForecastType fromString(String string) {
       return Optional
           .ofNullable(FORMAT_MAP.get(string))
           .orElseThrow(() -> new IllegalArgumentException(string));
   }
}`

2. Adding @JsonProperty to enums 
`  @JsonProperty("B")
   BASE("B"),
   @JsonProperty("O")
   OUTLIER("O"),
   @JsonProperty("E")
   SPECIAL_EVENT("E");`

None of them have worked.Tested by adding it in test class and it worked fine. But when i try with soup ui request after deploying code its throwing above error.
[Local Test class](https://i.stack.imgur.com/nWLJC.png)

**NOTE:** When i submit the same request by placing **"forecastType" : "SPECIAL_EVENT"**.
The request is giving correct response. 
 
Mounika
  • 1
  • 2
  • Please format your code correctly – Maurice Perry Jul 20 '23 at 06:44
  • I have formatted the code Please check now and update me if anything required – Mounika Jul 20 '23 at 08:44
  • Have you annotated the `ForecastType` field in whatever class contains it with `@JsonDeserialize(using = ForecastTypeDeserializer.class)`? – tgdavies Jul 20 '23 at 08:48
  • yes i have done it. '@NotNull(message = "Forecast type is mandatory field") @JsonDeserialize(using = ForecastTypeDeserializer.class) @JsonSerialize(using = ForecastTypeSerializer.class) private ForecastType forecastType;' – Mounika Jul 20 '23 at 08:49

0 Answers0