spring-projects / spring-projects/spring-data-rest
Updating value to NULL using Spring Data REST and PUT Method
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
We are using a Spring Data REST CRUD repository (1.0.0.RELEASE). On a PUT, it seems there is no way to set a property to null. If you send a null property (see JSON below), it is ignored.
{
"address1": null
}
I've tracked the code down to the following lines in spring-data-rest-webmvc RepositoryRestController.java. This code does not differentiate whether the client has explicitly sent a property with a null value (in which case, you want to set the property to null) as opposed to the client not sending the property at all (in which case, it should be ignored).
if(null != (incomingVal = attrMeta.get(incoming))) {
attrMeta.set(incomingVal, entity);
}
How would someone update a property to null? It seems like this is a real need.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in spring-data-rest-webmvc RepositoryRestController.java at the attrMeta lookup and setter logic named in the issue. Reproduce a PUT containing {"address1": null}, then compare it with a request that omits address1. Done means an explicitly supplied null can clear the property while an omitted property remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100