Hi,

I found these issues in GitHub issues tracker: #858 
<https://github.com/FasterXML/jackson-databind/issues/858> and #869 
<https://github.com/FasterXML/jackson-databind/issues/869>. 
As @TatuSaloranta explained, I understand that "required" attribute in 
@JsonProperty works only for creator parameters. Here is the a working 
example provided by Operatiay in #869 
<https://github.com/FasterXML/jackson-databind/issues/869#issuecomment-124442450>

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class MyObject {
    String req;

    String opt;

    @JsonCreator
    public MyObject(
            @JsonProperty(required = true,  value="req") String req,
            @JsonProperty(required = false, value="opt") String opt) {
        this.req = req;
        this.opt = opt;
    }
}


Maybe it is a bit more complex to add support for non creator parameter, as 
requested for the original example

public class MyObject {
    @JsonProperty(required=true)
    String req;

    String opt;
}


but I came up with an implementation that gives basic support for that. You 
can see my git commit here db0d6903 
<https://github.com/htmsousa/jackson-databind/commit/db0d690371ca9cf116c285e03027c00e4b3b3113>
 to 
see the code implementation and the test case provided by Operatiay.

Tatu, if you can provide some feedback on this, I can improve this code, 
maybe extend support for other deserializers and do a pull request.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to