You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

com.github.avatar21:enum-objectify

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.avatar21:enum-objectify

Java Enum object bean conversion Utilities

1.1.2
Source
mavenMaven
Version published
Maintainers
1
Source

enum-objectify

Java Enum bean object conversion Utilities

project build badge

  • method#1 - use the generic DescriptiveEnumObject as a receiver, then use EnumObjectUtils to do the conversion
    • example:
    class Test {
        public static void main(String[] args){
            DescriptiveEnumObject<SexEnum, Character> sexEnum = EnumObjectUtils.asDescriptiveEnumObject(DescriptiveEnumObject.class, SexEnum.FEMALE);
            System.out.println(String.format("sex enum = %s", gson.toJson(sexEnum)));
        }
    }
    
  • method#2 - inherit DescriptiveEnumObject and convert directly from EnumObjectUtils
    • example:
    // === enum class ... ===
    public enum SexEnum implements IDescriptiveEnum<Character> {
        MALE('M', "male"), FEMALE('F', "FEMALE");
        
        SexEnum(char code, String description) {
            // implement enum ...
        }
    }
    
    // === enum object class ===
    class SexEnumObject extends DescriptiveEnumObject<SexEnum, Character> {
        // implement constructor ...
        public SexEnumObject(SexEnum enumInstance) {
            super(enumInstance);
        }
    }
    
    // === usage ===
    public class TestMain {
        public static void main(String[] args) {
            Gson gson = new Gson();
            SexEnumObject mSexObj = EnumObjectUtils.asDescriptiveEnumObject(SexEnumObject.class, SexEnum.MALE);
            System.out.println("sex = "+gson.toJson(mSexOb));
         }
    }
    
  • Get enum by specifying code
    • example:
    // === usage ===
    public class TestMain {
        public static void main(String[] args) {
            SexEnum mSex = EnumObjectUtils.getByCode(SexEnum.class, "M"); 
        }
    }
    
  • List all possible values to EnumObject List
    • example:
    // === usage ===
    public class TestMain {
        public static void main(String[] args) {
            List<SexEnumObject> sexEnumObjList = EnumObjectUtils.asDescriptiveEnumObjectList(SexEnum.class, SexEnumObject.class);
                    System.out.println(String.format("SexEnum.values() as obj list = %s", gson.toJson(sexEnumObjList)));
        }
    }
    
  • List all possible values as EnumObject Map
    • example:
    // === usage ===
    public class TestMain {
        public static void main(String[] args) {
            Map<Character, SexEnumObject> sexEnumObjMap = EnumObjectUtils.asDescriptiveEnumObjectMap(SexEnum.class, SexEnumObject.class);
            System.out.println(String.format("SexEnum.values() as obj map = %s", gson.toJson(sexEnumObjMap))); 
        }
    }
    

FAQs

Package last updated on 05 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.