RanchoSoftware RanchoSoftware - 1 year ago 184
Java Question

What is the best way to save Java Enums using Firebase

I'm using Google's Firebase. I placed a Java Enum as one of the members in one of my model classes. When an instance is saved to the Firebase Database it throws an exception. What is the best way to resolve?

Answer Source

After additional research. Here is a workaround for Firebase 3.0.0. Apparently previous versions Firebase had more flexible support for Jackson that has been eliminated. Here's a Job class with enum that works (with the hacky code)

public class Job {
  public enum JobLifecycle  {
    New, inTransit, inStorage, delivered, signedOff;

  ...// other fields omitted
  JobLifecycle lifecycle;

  public Job(){

  public JobLifecycle getLifecycleAsEnum(){
    return lifecycle;

  // these methods are just a Firebase 9.0.0 hack to handle the enum
  public String getLifecycle(){
    if (lifecycle == null){
      return null;
    } else {
      return lifecycle.name();

  public void setLifecycle(String lifecycleString){
    if (lifecycleString == null){
      lifecycle = null;
    } else {
      this.lifecycle = JobLifecycle.valueOf(lifecycleString);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download