Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dual-use JAXB/JSON-B xml/json & @BeanParam form objects #117

Open
derekm opened this issue Sep 3, 2018 · 1 comment
Open

Allow dual-use JAXB/JSON-B xml/json & @BeanParam form objects #117

derekm opened this issue Sep 3, 2018 · 1 comment
Labels
Milestone

Comments

@derekm
Copy link
Contributor

derekm commented Sep 3, 2018

Allow objects to work with JAXB/JSON-B & @BeanParam.

Allowing dual-use POJOs helps unify JAX-RS resource definitions.

Consider two services, a GET and a POST. In order to support both JSON/XML and x-www-form-urlencoded, two POST definitions are currently needed (in recent version of Jersey). E.g.,

/**
 * Accepts answers to questions that map to Standard Data Set attributes.
 *
 * @author Derek Moore <a href="mailto:dmoore@fanthreesixty.com">dmoore@fanthreesixty.com</a>
 */
public interface AnswersResource {

    @GET
    @Consumes({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            })
    @Produces({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            })
    public List<QuestionAnswer> get(@QueryParam("flowId") UUID flowId);

    /**
     * Post an answer to a Standard Data Set question.
     * @param answer an answer to a Standard Data Set question
     * @return the answer as saved
     */
    @POST
    @Consumes({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            })
    @Produces({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            })
    public QuestionAnswer post(QuestionAnswer answer);

    /**
     * Form post an answer to a Standard Data Set question.
     * @param flowId the flow the question is in
     * @param orgId the id for the org that the question belongs to
     * @param customerId the customer answering the question
     * @param attributeKey the attribute the question answers
     * @param value the chosen value of the attribute
     * @param values the chosen values of the attribute
     * @return the answer as saved
     */
    @POST
    @Consumes({
            MediaType.APPLICATION_FORM_URLENCODED,
            })
    @Produces({
            MediaType.APPLICATION_JSON,
            MediaType.APPLICATION_XML,
            MediaType.TEXT_HTML,
            })
    public QuestionAnswer post(@NotNull @FormParam("flowId") UUID flowId,
                               @NotNull @FormParam("orgId") UUID orgId,
                               @NotNull @FormParam("customerId") UUID customerId,
                               @NotNull @FormParam("attributeKey") String attributeKey,
                               @FormParam("value") String value,
                               @FormParam("values") List<String> values);

}

Additional information is available in this old Jersey PR to unify Jersey's date parsing in support of unified JAXB xml/json & BeanParam form objects: https://github.com/jersey/jersey/pull/94

@andymc12
Copy link
Contributor

We discussed this on the September 12 meeting - here are the minutes for this item:

New issue: 117 - this might be a complicated scenario - might need some sort of “multi-purpose” annotation to indicate that the parameter could be a @BeanParam or an entity…

  • May not make sense if not currently supported on server side yet

I think this is a good idea, but may need to wait until a later release.

Thanks for opening this issue! Andy

@Emily-Jiang Emily-Jiang added this to the Future milestone Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants