question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Enum Type Converter ignored

See original GitHub issue

We have a customized enum like

  public enum Style {
    VALUE1(0),
    VALUE2(1);

    private final short code;

    Style(int i) {
      code = (short) i;
    }

    public short getCode() {
      return code;
    }

    public static Style valueOf(short code) {
      for(Style s : values()) {
        if (code == s.getCode()) {
          return s;
        }
      }
      return null;
    }
  }

and correpsonding value converter

@com.raizlabs.android.dbflow.annotation.TypeConverter public class StyleConverter
    extends TypeConverter<Short, Style> {

  @Override public Short getDBValue(Pass.Style style) {
    return style.getCode();
  }

  @Override public Pass.Style getModelValue(Short code) {
    return Pass.Style.valueOf(code);
  }
}

however, the converter is not used in the generated code. The code uses the builtin support for enum by using the enum’s name as representation in the database

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
trevjonezcommented, May 31, 2017

try adding the @TypeConverter annotation to your type converter implementation and just remove the typeConverter label from the column declaration site?

0reactions
marcuseducommented, May 31, 2017

@trevjonez Thank you so much, works. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Newtonsoft.Json Ignores TypeConverters and/or ...
Now we create our custom TypeSafeEnumJsonConverter class that implements the JsonConverter object, and will call our conversion helper ...
Read more >
InputRenderer ignores any defined enum custom converter
So if i look at this correctly, then for each Enum type any defined converter is ignored and the name of the enum...
Read more >
How to write custom converters for JSON serialization - .NET
Learn how to create custom converters for the JSON serialization classes that are provided in the System.Text.Json namespace.
Read more >
JPA 2.1 Attribute Converter - The better way to persist enums
Persisting enums with JPA 2.0 is possible, but there is no nice way to do it. Using the @Enumerated annotation, you can use...
Read more >
Enum TypeConverter and description in UI for Silverlight
Now my problem is that the telerik RadGridView seems to ignore the TypeConverter and just calls Enum.ToString(). Is there any way to force...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found