1

how can write condition 'if' type is no details other two fields are hide in json response. if possible i want to do it in pojo or bean ?

Using spring boot

  • spring data rest and hal.
  • pojo
  • MongoDB Repository

I want to show accountNo and Accountdetails if type="details"

{
   "Name":"Json",
   "lastName":"Amazon",
   "type":"Details",
   "accountNo":"12123",
   "AccountdetailsDetails":[ some details]
}

If type="noDetails" just show mentioned response.

{
   "Name":"Json", 
   "lastName":"Amazon",
   "type":"NoDetails"
}
  • Does this answer your question? [Ignore fields from Java object dynamically while sending as JSON from Spring MVC](https://stackoverflow.com/questions/23101260/ignore-fields-from-java-object-dynamically-while-sending-as-json-from-spring-mvc) – Vadzim Aug 12 '21 at 13:51

1 Answers1

2

I guess you need @JsonFilter. You can use this annotation to exclude some properties in your entity response.

What you need to do is Add this annotation with unique name in your entity file. Then serialize this entity values using filter class SimpleFilterProvider.

Take a look on https://www.logicbig.com/tutorials/misc/jackson/json-filter-annotation.html

Tamil.S
  • 403
  • 3
  • 14