2

I have an ASP.NET Web API application. It uses enums for some fixed sets of states or types. Now I need to extend enum to support more values. But it will break backwards compatibility so I need to create new version of method. Is it better to use strings for this purpose? I suppose I can easily extend a list of possible string values and this changes don't require new version of api method. What do you think?
UPDATE: I have enum

public enum ElementTypes
{
    Tree,
    Test,
    Post
}

and I need to add two new items into this enum.

1

1 Answer 1

2

Its best to use enums serialised as strings and use versioning to deal with backwards compatibility issues.

This gives you the type safety of enums in your c# code, but retains the meaningful values in your json and consuming apps.

Maybe add more info about your particular backwards compatibility issue? Adding more values to an enum should not necessarily cause a problem. But obviously using strings as input does not solve all possible backwards compatibility issues, so you need versioning in any case

3
  • I added example. So I see it requires new version anyway. I mean if I use list of constant strings in api and I need to return new string constant - new version is required here anyway, right? Commented Dec 14, 2016 at 11:17
  • 1
    it (always) requires a new version. but its not clear why it would not be backward compatible with the previous version
    – Ewan
    Commented Dec 14, 2016 at 11:18
  • Yeah, I see my explanation is a bit unclear. I mean situation when I just add new string to existing list of constants without new version. So consumer didn't expect to recieve this value in response. I need to create a new version. Commented Dec 14, 2016 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.