klenium klenium - 28 days ago 4x
Java Question

Why javax.json containts only interfaces?

javax.json documentation

An example from the docs:

JsonArray value = Json.createArrayBuilder()
.add("type", "home")
.add("number", "212 555-1234"))
.add("type", "fax")
.add("number", "646 555-4567"))

is an interface, not a class, and a variable's type can't be an interface. So where is
class JsonArray
? I guess the package
contains it, but why isn't it documented?

Not a big deal though, I've already read the interfaces' details, it shows all the needed methods/constructors/return types, and now I know how to use these "classes".


Java EE is a specification; it has no implementation. It relies on third-parties to implement the specification. javax.json package is part (or will eventually be part of) java EE. Therefore, including this jar will only provide you with the interface to a json api. You will be required to provide an implementation at runtime for it to work. Usually, your code should be agnostic to the implementation even if, in the fact, this is easier said than done.