Skip to content

Conversation

@DSteve595
Copy link

This mapper simply uses the enum's name to serialize and deserialize any enum class without having to write a converter.

Tested with:

@JsonObject
public enum TestEnum {
    First, Second, Third
}

Serializing a TestEnum to JSON seems to work, but I can't be 100% sure as I can't figure out how to use this project's test framework. It did spit out proper-looking JSON when I tested it by just serializing a list of them, but I haven't been able to get the annotation processor working in my project, so I currently can't test with any custom classes.

Deserializing this object:

{
  "the_enum": "First",
  "another_enum": "Third"
}

with LoganSquare.parseMap() yields this:
image

which looks good!

I mainly wanted to do this because after switching my project over from Gson, I missed the ease of how it handled Enums. This still needs work but I think it's a good starting point. Hopefully someone better versed in annotation processing can figure out a clean way to have field names overridden (like @SerializedName on an enum value in Gson).

Thanks for the great library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant