Why do all model objects strictly enforce use of the Builder pattern to instantiate?
I'm curious as to why this is strictly enforced. The objects already have JSON annotations, which is great. I'd like to be able to go both ways with JSON. I'd like to be able to make the code below work without having to write a translation, but since the NetworkConfig only has a private constructor and no setters, Jackson doesn't know what to do.
I'd be happy to make the PR with the changes to the model objects, but I have to think that with such strict enforcement of this pattern, there must be a good reason for it. Please help me to understand it.
@PostMapping("/")
public @ResponseBody String createNetwork(@RequestBody NetworkConfig config) {
//do something with the config
}
I don't think this is true for all model classes, many of them have static factory methods with a @JsonCreator that allows Jackson to deserialize JSON into the class and which I think would work for your example.
NetworkConfig may have been an oversight - and I'm not sure how it is even working today - so a PR that adds a @JsonCreator method would definitely be welcome.
@mattnworb - I see that now. I was somehow looking at a very old version of the library. Thanks for the quick response.