Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4051

Set POJO field value based on the value of another field in Spring Boot

$
0
0

I have a simple POJO class

class POJO{private boolean isEnabled,private String field}

I have a controller that accepts RequestBody of type POJO, as part of a change I want to include a validation such that when isEnabled is true in the RequestBody set the value of field to "TEST" (value of field in RequestBody will be null) and when isEnabled is false set the value of field to value received from RequestBody

I can implement a if...else... on the controller/service but this involves a lot of code replication especially since i have multiple fields to set, Is there a way i can incorporate this validation within the POJO class itself?


Viewing all articles
Browse latest Browse all 4051

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>