jansupol / jsonbapi

0 stars 0 forks source link

Why are BinaryDataStrategy and PropertyOrderStrategy no enums? #44

Closed jansupol closed 7 years ago

jansupol commented 7 years ago

I noticed at least 2 elements of javax.json.bind.config, BinaryDataStrategy and PropertyOrderStrategy are final classes defining nothing but static string constants like

/**
  * Using this strategy, binary data is encoded as a byte array.
  * Default encoding strategy.
  */
  public static final String BYTE = "BYTE";

All of these constants contain nothing but the name of the constants. This has all symptoms of an enum so why weren't these two defined as enums?

Affected Versions

[1.0 Public Review]

jansupol commented 6 years ago
jansupol commented 7 years ago

@glassfishrobot Commented Reported by keilw

jansupol commented 7 years ago

@glassfishrobot Commented @m0mus said: It's done this way to allow vendors adding implementation specific Strategies and work with them in consistent way.

jansupol commented 7 years ago

@glassfishrobot Commented keilw said: Two of them are interfaces, but how would you extend final class BinaryDataStrategy or final class PropertyOrderStrategy? The final classes are just like enums, you cannot extend them. With those constant collections in an interface it makes sense, but how would they add anything to a final class?

jansupol commented 7 years ago

@glassfishrobot Commented @m0mus said: These classes are NOT designed to be extended. They holds constants supported by the API.

JsonbConfig has withPropertyOrderStrategy and withBunaryDataStrategy methods. Both of them accept a String parameter. In case vendors (not users!) want to support more strategies than defined in the API they need to create their own constants and use it in config this way:

withPropertyOrderStrategy(VendorPropertyOrderStrategy.WHATEVER);

jansupol commented 7 years ago

@glassfishrobot Commented keilw said: Thanks for explaining the difference. Vendors are of course users or consumers of the JSR/API/SPI JSF among other cases showed, enums can be tricky in certain cases when you try to extend them.

jansupol commented 7 years ago

@glassfishrobot Commented Was assigned to roman.grigoriadi

jansupol commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JSONB_SPEC-44

jansupol commented 7 years ago

@glassfishrobot Commented Marked as won't fix on Friday, March 3rd 2017, 5:51:22 am