juneau-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Blackmon (JIRA)" <j...@apache.org>
Subject [jira] [Created] (JUNEAU-57) seamless serialization and parsing of string fields to/from enum
Date Wed, 14 Jun 2017 21:59:00 GMT
Steve Blackmon created JUNEAU-57:

             Summary: seamless serialization and parsing of string fields to/from enum
                 Key: JUNEAU-57
                 URL: https://issues.apache.org/jira/browse/JUNEAU-57
             Project: Juneau
          Issue Type: Improvement
            Reporter: Steve Blackmon

i’m working to replace jackson with juneau, while maintaining the ability to define certain
fields as enumerations rather than strings.

jackson ObjectMapper handles enums transparently, presumably juneau could too?

relevant piece of the pojo is below.

once this is working, the following test snippets should pass:

public void testEnumParse() throws Exception {
  String json = "{\"type\":\"message_create\"}";
  DirectMessageEvent event = JsonParser.DEFAULT.parse(json, DirectMessageEvent.class);

public void testEnumSerialize() throws Exception {
  DirectMessageEvent event = new DirectMessageEvent();
  String json = JsonSerializer.DEFAULT.serialize(event);


public class DirectMessageEvent implements Serializable

@BeanProperty(name = "type")
private DirectMessageEvent.Type type = DirectMessageEvent.Type.fromValue("message_create");

@BeanProperty(name = "type")
public DirectMessageEvent.Type getType() {
    return type;

@BeanProperty(name = "type")
public void setType(DirectMessageEvent.Type type) {
    this.type = type;

public static enum Type {

    private final String value;
    private static Map<String, DirectMessageEvent.Type> constants = new HashMap<String,

    static {
        for (DirectMessageEvent.Type c: values()) {
            constants.put(c.value, c);

    private Type(String value) {
        this.value = value;

    public String toString() {
        return this.value;

    public static DirectMessageEvent.Type fromValue(String value) {
        DirectMessageEvent.Type constant = constants.get(value);
        if (constant == null) {
            throw new IllegalArgumentException(value);
        } else {
            return constant;



This message was sent by Atlassian JIRA

View raw message