Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

@Accept: Add support to other MediaType #221

Description

@eric-taix

I'm trying to use a JSON API. The API defines a specific mime type => application/vnd.kippt.YYYYMMDD+json (where YYYYMMDD is the date of the API you want to use). This way they introduce a versioned API.

I'm not saying that it's a good solution to version API, but I just try to use their API !

Width @accept annotation, I can only use MediaType which is an Enum. With class Spring MediaType, I can create my own Mediatype.

I think that adding two attributes to @accept annotations would be enough (type and subtype).

Activity

  1. pyricau commented on Jun 28, 2012

    @pyricau
    Contributor

    I think that's a quite valid use case. @a-thomas what do you think ?

  2. pyricau commented on Jun 28, 2012

    @pyricau
    Contributor

    For @Accept, we can either :

    • Replace the MediaType enum with a class holding String constants, and update @Accept to take a String value() param
    • Keep the current value() parameter that can have a default empty value, and add a new stringType() (we need to find a better name) that accepts Strings.

    I think the first option would be more universal. And it should be retrocompatible, if we keep the same qualified name for MediaType.

    In the generated code, instead of:

    httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

    We would do:

    httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType("text/json")));
  3. pyricau commented on Jun 28, 2012

    @pyricau
    Contributor

    And by the way, @a-thomas , why did we create our own MediaType enum instead of using org.springframework.http.MediaType ?

  4. a-thomas commented on Jul 3, 2012

    @a-thomas
    Contributor

    I think I did that because Spring dependencies are not available in androidannotations project. So, I have created our own MediaType to use the "native" annotation validation.

    See:

    @Retention(RetentionPolicy.SOURCE)
    @Target({ ElementType.METHOD, ElementType.TYPE })
    public @interface Accept {
        MediaType value();
    }
  5. a-thomas commented on Jul 3, 2012

    @a-thomas
    Contributor

    Replace the MediaType enum with a class holding String constants, and update @accept to take a String value() param

    I totally agree with you. I create an issue.

  6. pyricau commented on Jul 3, 2012

    @pyricau
    Contributor

    You're right :) .

  7. added a commit that references this issue on Aug 2, 2012
  8. pyricau commented on Aug 2, 2012

    @pyricau
    Contributor

    Fixed by cd09c11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions