How to distinguish between null and not provided values for partial updates in Spring Rest Controller

后端 未结 7 825
囚心锁ツ
囚心锁ツ 2020-12-04 17:32

I\'m trying to distinguish between null values and not provided values when partially updating an entity with PUT request method in Spring Rest Controller.

Consider

相关标签:
7条回答
  • 2020-12-04 18:27

    Maybe too late for an answer, but you could:

    • By default, don't unset 'null' values. Provide an explicit list via query params what fields you want to unset. In such a way you can still send JSON that corresponds to your entity and have flexibility to unset fields when you need.

    • Depending on your use case, some endpoints may explicitly treat all null values as unset operations. A little bit dangerous for patching, but in some circumstances might be an option.

    0 讨论(0)
提交回复
热议问题