0

I have the following problem:

I have an endpoint with request body like ContactRequest:

public class ContactRequest{
  private String message;
  private Object result;
}

BUT this endpoint is invoked by some other service with JSON payload with upper case:

{
  "Message": "Some text",
  "Result": "Resultsdsddwd"
}

I try to use pattern in openapi.yml but I think it's not the correct fix for my problem because in code I use ContactRequest object with lower case fields...

 ContactRequest:
      pattern: ^[A-Za-z\s_-]+$
      type: object
      required:
        - id
        - status
        - message

My endpoint:

public CommandResponse save(
       ContactRequest contactRequest){
...
}

Did someone have similar problem? I can't change the request body

PS. Maybe there is something like @JsonAlias in OpenApi.yml generator file?

UPDATE Maybe should I use global settings to set case insensitive?

My build.gradle file:

implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
    implementation group: 'org.modelmapper', name: 'modelmapper', version: '2.3.6'
Matley
  • 1,953
  • 4
  • 35
  • 73
  • Does this answer your question -- [Jackson JSON field mapping capitalization](https://stackoverflow.com/q/15303110/113116)? – Helen Aug 03 '20 at 10:45
  • @Helen I dont thnk so unfortunately...I can;t modify a class that is generated by openapi.yaml generation file – Matley Aug 03 '20 at 11:01

1 Answers1

0

I think you can try this solution if it works in your case:

@JsonNaming(PropertyNamingStrategy.LowerCaseStrategy.class)
public class ContactRequest{
  private String message;
  private Object result;
}

Built-in strategies are: KEBAB_CASE, LOWER_CASE, SNAKE_CASE, UPPER_CAMEL_CASE

https://www.baeldung.com/jackson-advanced-annotations

jaop
  • 268
  • 2
  • 8
  • Yes but ContactRequest objet is generated by openapi so I can change this object only by openapi.yaml generation file – Matley Aug 03 '20 at 10:52