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

Support Serializer for Enum #134

Closed
5 tasks done
tangcent opened this issue Sep 27, 2019 · 1 comment
Closed
5 tasks done

Support Serializer for Enum #134

tangcent opened this issue Sep 27, 2019 · 1 comment
Assignees
Labels
type: bug Something isn't working type: enhancement New feature or request

Comments

@tangcent
Copy link
Owner

tangcent commented Sep 27, 2019

  • Let’s define the following Enum:
    public enum Distance {

        KILOMETER("km", 1000),

        MILE("miles", 1609.34),

        METER("meters", 1),

        INCH("inches", 0.0254),

        CENTIMETER("cm", 0.01),

        MILLIMETER("mm", 0.001);
        private String unit;
        private final double meters;

        private Distance(String unit, double meters) {
            this.unit = unit;
            this.meters = meters;
        }

        public String getUnit() {
            return unit;
        }

        public double getMeters() {
            return meters;
        }
    }
  • 1.Default Enum Representation
    By default, EasyApi will represent Java Enums as simple String – for example:
private Distance distance;

Will be equivalent to

    /**
     * @see Distance
     */
    private String distance;
  • 2.Support Custom Rules
  • 2.1.Convert Enum as special field - for example:
json.rule.enum.convert[your enum class]=your enum class#value field

abbreviated:

json.rule.enum.convert[your enum class]=#value field
  • 2.2.Convert Enum as special method(always getter) - for example:
json.rule.enum.convert[your enum class]=your enum class#method

abbreviated:

json.rule.enum.convert[your enum class]=~#method
  • 2.3.Support use script as filter - for example:
json.rule.enum.convert[groovy:it.extend("com.itangcent.Describable")]=~#desc

see jackson-serialize-enums


@tangcent tangcent added type: bug Something isn't working type: enhancement New feature or request labels Sep 27, 2019
@tangcent tangcent self-assigned this Sep 27, 2019
@tangcent
Copy link
Owner Author

support by #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant