spring-projects / spring-projects/spring-data-rest
Custom Serializers cannot apply patch method [DATAREST-1566]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
huisezhiwei opened DATAREST-1566 and commented
I have a Dictionary entity bean contain fields like "dictCode" and "dictValue". then define a DTO class contain fields like "code" and "value" . finally register a customer Module to serializer
public class DictionaryMapper extends SimpleModule {
@Override
public void setupModule(SetupContext context) {
SimpleSerializers serializer = new SimpleSerializers();
serializer.addSerializer(Dictionary.class, new JsonSerializer<Dictionary>() {
@Override
public void serialize(Dictionary value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeNumberField("id", value.getId());
gen.writeStringField("code", value.getDictCode());
gen.writeStringField("value", value.getDictValue());
}
@Override
public boolean isUnwrappingSerializer() {
return true;
}
});
context.addSerializers(serializer);
SimpleDeserializers deserializers = new SimpleDeserializers();
deserializers.addDeserializer(Dictionary.class, new JsonDeserializer<Dictionary>() {
@Override
public Dictionary deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = p.getCodec().readTree(p);
ObjectMapper op = new ObjectMapper();
DictionaryResource resource = op.convertValue(node, DictionaryResource.class);
return new Dictionary(resource);
}
});
context.addDeserializers(deserializers);
}
}
everything is ok in get post and put method , bug in patch method request . the JsonNode always return EmptyJson ("{}")
I try to debug and find the doMerge method on the DomainObjectReader will remove the DTO fields becasue mappedProperties.isWritableProperty return false .
No further details from DATAREST-1566
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.
Assessment
This issue has not been assessed yet.