0

I get a Json response from upstream response as shown below.

{
    "fieldone": {
    "header": {
    "requestId": "1234",
    "applicationName": "office",
    "status": "SUCCESS"
    },
    "lineLevel": [{
    "ou": "1025854560",
    "status": "REJECT"
    }]
    }
}

LineLevel field may or may not be part of JSON response every time.we may get or may not.when we were not getting it it was causing issue .to resolve it I have tried with @jsonIgnore at property level but its ignoring the field when we get that particular field as part of response.

Tried @JsonIgnoreProperties at class level but its causing issue when respective proeprty is not present in Json response

can any provide any pointers in resolving it.Irrespective of whether LineLevel property is present or not in Json response I should be go ahead with my process

javalearner
  • 347
  • 2
  • 7
  • 21

2 Answers2

0

You can use

@JsonInclude(Include.NON_NULL)
LineLevel lineLevel

That will convert this field, only when it's not null.

You can get examples here

Pospolita Nikita
  • 635
  • 5
  • 15
0

Keeping the single responsibility principle in mind, I strongly encourage you to use different classes for the persistence entity and for mapping the JSON response coming the from the upstream server.

If the boilerplate code of mapping one object to another is a concern, use mapping frameworks such as MapStruct.

cassiomolin
  • 124,154
  • 35
  • 280
  • 359